zcode: the Start Plan's 405 block is said for what it is, not only as a firewall (#425: ZCode 405 Method Not Allowed on GLM-5.3-Flash from DeepSeek Harness, while zcode2api works with the same account) — zcode.z.ai answers a Start Plan request it turns away with 405 "request has been blocked due to unusual activity" (code 3012 "method not allowed"), which magpie read as Alibaba Cloud's firewall blocking the address and told the user to wait or switch network. zcode2api's own write-ups (a137460387/zcode2api "3012 的根因与修复", gakiyukr/zcode2api-plus request.go) find the endpoint checks what a request carries and takes only one with ZCode's own system prompt, which zcode2api injects; magpie's endpoint, method and protocol are the same as theirs, and magpie doesn't pretend to be ZCode. On a Start Plan account the 405 / 3012 / block page now reads "ZCode's Start Plan turns away requests that don't come from the ZCode app itself, and magpie doesn't pretend to be it; it can also be a network block of this IP. Use an account with a GLM Coding Plan, or add another provider to this group", in place of the generic hint, to the agent and in the trace, where the Routing page gives it on its own line in English or Chinese; the group still goes on to its next member. A Coding Plan account and every other provider keep the generic hint. Requests, headers and prompts are unchanged. TestZCodeStartBlockedSaid and routing-zcode-blocked.test.cjs fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (TestUserPath, a load flake, passes alone); routing-zcode-blocked, routing-blocked, routing-wb-refused, click-scroll, old-webkit pass.
This commit is contained in:
@@ -1512,6 +1512,7 @@ const I18N = {
|
||||
"It said: {error}": "原话:{error}",
|
||||
"WorkBuddy refuses chats from Codex and Claude Code (their system prompt); use it from Hermes, OpenCode or Pi, or add another provider to this group": "WorkBuddy 会拒绝来自 Codex 和 Claude Code 的对话(因为它们的系统提示词);请在 Hermes、OpenCode 或 Pi 里使用它,或在这个分组里再加一个供应商",
|
||||
"the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy": "供应商的网络防火墙拦截了来自这个 IP 的请求;请稍等一会儿,或换个网络或代理",
|
||||
"ZCode's Start Plan turns away requests that don't come from the ZCode app itself, and magpie doesn't pretend to be it; it can also be a network block of this IP. Use an account with a GLM Coding Plan, or add another provider to this group": "ZCode 体验套餐会拒绝不是来自 ZCode 客户端本身的请求,magpie 不会冒充它;也可能是网络拦截了这个 IP。请改用有 GLM Coding Plan 的账号,或在这个分组里加上其他供应商",
|
||||
"Show the latest request that failed": "查看最近一个失败的请求",
|
||||
"rate limited": "限流",
|
||||
"out of credit": "余额不足",
|
||||
|
||||
@@ -486,7 +486,10 @@
|
||||
const WB_REFUSED = "WorkBuddy refuses chats from Codex and Claude Code (their system prompt); use it from Hermes, OpenCode or Pi, or add another provider to this group";
|
||||
// what it adds to a vendor's edge firewall's block page (provider.BlockedHint)
|
||||
const BLOCKED = "the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy";
|
||||
const HINTS = [WB_REFUSED, BLOCKED];
|
||||
// what it says of ZCode's Start Plan turning a request away (#425,
|
||||
// provider.ZCodeStartBlockedHint), in place of BLOCKED
|
||||
const ZCODE_BLOCKED = "ZCode's Start Plan turns away requests that don't come from the ZCode app itself, and magpie doesn't pretend to be it; it can also be a network block of this IP. Use an account with a GLM Coding Plan, or add another provider to this group";
|
||||
const HINTS = [WB_REFUSED, BLOCKED, ZCODE_BLOCKED];
|
||||
|
||||
function trySaid(r, i) {
|
||||
const tr = r.tries[i], w = tried(r, tr), agent = agentName(r.agent);
|
||||
|
||||
@@ -549,6 +549,15 @@ firewall blocked this IP; wait, or switch network or proxy) is on its own
|
||||
line in English and Chinese; another 405 gets none, and picking the request
|
||||
leaves the page where it is. Chromium and WebKit, API faked.
|
||||
|
||||
`routing-zcode-blocked.test.cjs` opens a request ZCode's Start Plan turned
|
||||
away (#425: 405 "request has been blocked due to unusual activity") on the
|
||||
Routing page: what the gateway made of it is given without the hint it adds,
|
||||
and the hint (ZCode takes only its own app's requests and magpie doesn't
|
||||
pretend to be it, or the network blocked this IP; use a GLM Coding Plan or
|
||||
another provider in the group) is on its own line in English and Chinese;
|
||||
another 405 gets none, and picking the request leaves the page where it is.
|
||||
Chromium and WebKit, API faked.
|
||||
|
||||
`routing-shape.test.cjs` opens a group request whose first member answered
|
||||
422 because its API couldn't read the request (#350: SuperGrok and Codex's
|
||||
additional_tools item) and whose next member answered: the Routing page says
|
||||
@@ -869,7 +878,7 @@ reads shows none of it. English and Chinese, Chromium and WebKit, with
|
||||
With Node.js and Playwright available:
|
||||
|
||||
```sh
|
||||
node --test internal/gui/tests/menu-scroll.test.cjs internal/gui/tests/click-scroll.test.cjs internal/gui/tests/panel-fold.test.cjs internal/gui/tests/rollup-short.test.cjs internal/gui/tests/panel-routing.test.cjs internal/gui/tests/gateway-fold.test.cjs internal/gui/tests/routing-kind.test.cjs internal/gui/tests/balance-fix.test.cjs internal/gui/tests/cli-update.test.cjs internal/gui/tests/login-import.test.cjs internal/gui/tests/agy-launch.test.cjs internal/gui/tests/currency.test.cjs internal/gui/tests/usage-ledger.test.cjs internal/gui/tests/update-check.test.cjs internal/gui/tests/omarchy.test.cjs internal/gui/tests/brand.test.cjs internal/gui/tests/library-loading.test.cjs internal/gui/tests/provider-typed.test.cjs node --test internal/gui/tests/signin-callback.test.cjs internal/gui/tests/routing-steady.test.cjs internal/gui/tests/old-webkit.test.cjs internal/gui/tests/session-terminal.test.cjs internal/gui/tests/text-size.test.cjs internal/gui/tests/zcode-site.test.cjs internal/gui/tests/rail-tip.test.cjs internal/gui/tests/sync-update.test.cjs internal/gui/tests/plugin-signin.test.cjs internal/gui/tests/plugin-market.test.cjs internal/gui/tests/s3-sync.test.cjs internal/gui/tests/routing-wb-refused.test.cjs internal/gui/tests/routing-blocked.test.cjs internal/gui/tests/routing-shape.test.cjs internal/gui/tests/market-have.test.cjs internal/gui/tests/sessions-today.test.cjs internal/gui/tests/routing-side-calls.test.cjs internal/gui/tests/import-all-skills.test.cjs internal/gui/tests/routing-flood.test.cjs internal/gui/tests/routing-busy.test.cjs internal/gui/tests/own-skill.test.cjs internal/gui/tests/routing-manual.test.cjs internal/gui/tests/tray-usages.test.cjs internal/gui/tests/provider-remove.test.cjs internal/gui/tests/signin-link.test.cjs internal/gui/tests/tray-inuse.test.cjs internal/gui/tests/codex-auto-reset.test.cjs internal/gui/tests/routing-auto-reset.test.cjs internal/gui/tests/claude-usage-asked.test.cjs internal/gui/tests/claude-risk.test.cjs internal/gui/tests/library-toggle-status.test.cjs internal/gui/tests/library-all.test.cjs internal/gui/tests/routing-reroute-title.test.cjs internal/gui/tests/plain-names.test.cjs internal/gui/tests/panel-effort.test.cjs internal/gui/tests/agent-models-all-hidden.test.cjs internal/gui/tests/omp-roles.test.cjs internal/gui/tests/claude-effort.test.cjs internal/gui/tests/remote-magpie.test.cjs internal/gui/tests/qoder-cn-tile.test.cjs internal/gui/tests/provider-levels-scroll.test.cjs internal/gui/tests/signin-paste-codex.test.cjs internal/gui/tests/usage-alert.test.cjs internal/gui/tests/quota-families.test.cjs internal/gui/tests/provider-search.test.cjs internal/gui/tests/webdav-settings-refresh.test.cjs internal/gui/tests/lan-docker.test.cjs internal/gui/tests/plugin-key-hint.test.cjs internal/gui/tests/update-hide.test.cjs internal/gui/tests/tray-logos.test.cjs internal/gui/tests/routing-proxy.test.cjs internal/gui/tests/sse-body.test.cjs internal/gui/tests/remote-group-served.test.cjs internal/gui/tests/plugin-move-overflow.test.cjs internal/gui/tests/routing-time.test.cjs internal/gui/tests/unlisted-models.test.cjs internal/gui/tests/plugin-updates.test.cjs internal/gui/tests/request-archive.test.cjs internal/gui/tests/group-member-fast.test.cjs internal/gui/tests/providers-off-fold.test.cjs internal/gui/tests/account-return.test.cjs internal/gui/tests/usage-ledger-detail.test.cjs internal/gui/tests/usage-ledger-chart.test.cjs internal/gui/tests/panel-usage.test.cjs internal/gui/tests/usage-refresh.test.cjs internal/gui/tests/usage-ledger-content.test.cjs internal/gui/tests/claude-direct.test.cjs internal/gui/tests/signin-again.test.cjs internal/gui/tests/sessions-calendar-fill.test.cjs internal/gui/tests/editor-short-window.test.cjs internal/gui/tests/group-from-model-add.test.cjs internal/gui/tests/sync-other-kind.test.cjs internal/gui/tests/web-page.test.cjs internal/gui/tests/balance-parts.test.cjs internal/gui/tests/search-api.test.cjs internal/gui/tests/provider-file-error.test.cjs
|
||||
node --test internal/gui/tests/menu-scroll.test.cjs internal/gui/tests/click-scroll.test.cjs internal/gui/tests/panel-fold.test.cjs internal/gui/tests/rollup-short.test.cjs internal/gui/tests/panel-routing.test.cjs internal/gui/tests/gateway-fold.test.cjs internal/gui/tests/routing-kind.test.cjs internal/gui/tests/balance-fix.test.cjs internal/gui/tests/cli-update.test.cjs internal/gui/tests/login-import.test.cjs internal/gui/tests/agy-launch.test.cjs internal/gui/tests/currency.test.cjs internal/gui/tests/usage-ledger.test.cjs internal/gui/tests/update-check.test.cjs internal/gui/tests/omarchy.test.cjs internal/gui/tests/brand.test.cjs internal/gui/tests/library-loading.test.cjs internal/gui/tests/provider-typed.test.cjs node --test internal/gui/tests/signin-callback.test.cjs internal/gui/tests/routing-steady.test.cjs internal/gui/tests/old-webkit.test.cjs internal/gui/tests/session-terminal.test.cjs internal/gui/tests/text-size.test.cjs internal/gui/tests/zcode-site.test.cjs internal/gui/tests/rail-tip.test.cjs internal/gui/tests/sync-update.test.cjs internal/gui/tests/plugin-signin.test.cjs internal/gui/tests/plugin-market.test.cjs internal/gui/tests/s3-sync.test.cjs internal/gui/tests/routing-wb-refused.test.cjs internal/gui/tests/routing-blocked.test.cjs internal/gui/tests/routing-zcode-blocked.test.cjs internal/gui/tests/routing-shape.test.cjs internal/gui/tests/market-have.test.cjs internal/gui/tests/sessions-today.test.cjs internal/gui/tests/routing-side-calls.test.cjs internal/gui/tests/import-all-skills.test.cjs internal/gui/tests/routing-flood.test.cjs internal/gui/tests/routing-busy.test.cjs internal/gui/tests/own-skill.test.cjs internal/gui/tests/routing-manual.test.cjs internal/gui/tests/tray-usages.test.cjs internal/gui/tests/provider-remove.test.cjs internal/gui/tests/signin-link.test.cjs internal/gui/tests/tray-inuse.test.cjs internal/gui/tests/codex-auto-reset.test.cjs internal/gui/tests/routing-auto-reset.test.cjs internal/gui/tests/claude-usage-asked.test.cjs internal/gui/tests/claude-risk.test.cjs internal/gui/tests/library-toggle-status.test.cjs internal/gui/tests/library-all.test.cjs internal/gui/tests/routing-reroute-title.test.cjs internal/gui/tests/plain-names.test.cjs internal/gui/tests/panel-effort.test.cjs internal/gui/tests/agent-models-all-hidden.test.cjs internal/gui/tests/omp-roles.test.cjs internal/gui/tests/claude-effort.test.cjs internal/gui/tests/remote-magpie.test.cjs internal/gui/tests/qoder-cn-tile.test.cjs internal/gui/tests/provider-levels-scroll.test.cjs internal/gui/tests/signin-paste-codex.test.cjs internal/gui/tests/usage-alert.test.cjs internal/gui/tests/quota-families.test.cjs internal/gui/tests/provider-search.test.cjs internal/gui/tests/webdav-settings-refresh.test.cjs internal/gui/tests/lan-docker.test.cjs internal/gui/tests/plugin-key-hint.test.cjs internal/gui/tests/update-hide.test.cjs internal/gui/tests/tray-logos.test.cjs internal/gui/tests/routing-proxy.test.cjs internal/gui/tests/sse-body.test.cjs internal/gui/tests/remote-group-served.test.cjs internal/gui/tests/plugin-move-overflow.test.cjs internal/gui/tests/routing-time.test.cjs internal/gui/tests/unlisted-models.test.cjs internal/gui/tests/plugin-updates.test.cjs internal/gui/tests/request-archive.test.cjs internal/gui/tests/group-member-fast.test.cjs internal/gui/tests/providers-off-fold.test.cjs internal/gui/tests/account-return.test.cjs internal/gui/tests/usage-ledger-detail.test.cjs internal/gui/tests/usage-ledger-chart.test.cjs internal/gui/tests/panel-usage.test.cjs internal/gui/tests/usage-refresh.test.cjs internal/gui/tests/usage-ledger-content.test.cjs internal/gui/tests/claude-direct.test.cjs internal/gui/tests/signin-again.test.cjs internal/gui/tests/sessions-calendar-fill.test.cjs internal/gui/tests/editor-short-window.test.cjs internal/gui/tests/group-from-model-add.test.cjs internal/gui/tests/sync-other-kind.test.cjs internal/gui/tests/web-page.test.cjs internal/gui/tests/balance-parts.test.cjs internal/gui/tests/search-api.test.cjs internal/gui/tests/provider-file-error.test.cjs
|
||||
```
|
||||
|
||||
If Playwright is installed outside the repository, set `NODE_PATH` to the
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// ZCode's Start Plan turning a request away (#425: 405 "request has been
|
||||
// blocked due to unusual activity", code 3012): the Routing page gives
|
||||
// what the gateway made of it, and apart from that what it means (ZCode
|
||||
// takes only its own app's requests, or the network blocked the address,
|
||||
// and what to use instead), in the page's language.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const now = new Date();
|
||||
const day = [now.getFullYear(), now.getMonth() + 1, now.getDate()].map((n) => String(n).padStart(2, "0")).join("-");
|
||||
const at = (i) => new Date(now.getTime() - (i + 1) * 60e3).toISOString();
|
||||
const hint = "ZCode's Start Plan turns away requests that don't come from the ZCode app itself, and magpie doesn't pretend to be it; it can also be a network block of this IP. Use an account with a GLM Coding Plan, or add another provider to this group";
|
||||
const vendor = "ZCode: 405 Method Not Allowed";
|
||||
const key = { id: "zcode", provider: "zcode", name: "ZCode", kind: "provider", model: "GLM-5.3-Flash" };
|
||||
// newest first: the block, then another 405 with nothing to add
|
||||
const errs = [vendor + " — " + hint, "ZCode: 405 Method Not Allowed", "", "", "", ""];
|
||||
const routes = errs.map((error, i) => {
|
||||
const status = error ? 405 : 200;
|
||||
return {
|
||||
id: 100 - i, seq: 100 - i, time: at(i), agent: "claude", model: "zcode/GLM-5.3-Flash", provider: "zcode",
|
||||
order: [key], tries: [{ id: key.id, model: key.model, start: at(i), done: true, status, ms: 400, ...(error ? { error } : {}) }],
|
||||
done: true, status, ms: 400, ...(error ? { error } : {}),
|
||||
};
|
||||
});
|
||||
|
||||
function serve(lang) {
|
||||
const state = { agents: [{ id: "claude", name: "Claude Code", path: "/test/settings.json", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json(state);
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/gateway/trace") {
|
||||
if (url.searchParams.get("wait")) await new Promise((r) => setTimeout(r, 20e3));
|
||||
return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
||||
}
|
||||
if (url.pathname === "/api/gateway/history") {
|
||||
const d = url.searchParams.get("day");
|
||||
return json({ cut: false, days: [{ day, requests: routes.length }], routes: d ? routes : [] });
|
||||
}
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
const want = {
|
||||
en: { said: "It said: " + vendor, hint },
|
||||
zh: { said: "原话:" + vendor, hint: "ZCode 体验套餐会拒绝不是来自 ZCode 客户端本身的请求,magpie 不会冒充它;也可能是网络拦截了这个 IP。请改用有 GLM Coding Plan 的账号,或在这个分组里加上其他供应商" },
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh"]) {
|
||||
test(`${engine} ${lang}: ZCode's Start Plan block says what it means`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 760 }, reducedMotion: "reduce" });
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang));
|
||||
t.after(async () => {
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-zcode-blocked.png`), fullPage: true });
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
await page.goto("http://magpie.test/?view=routing");
|
||||
await page.locator(".rt-day").nth(1).click();
|
||||
await page.locator(".rt-req").nth(errs.length - 1).waitFor();
|
||||
|
||||
const steps = async () => page.locator(".rt-steps li").evaluateAll((ls) => ls.map((l) => [l.className, l.textContent]));
|
||||
const row = page.locator(".rt-req").nth(0);
|
||||
const was = await row.evaluate((e) => e.getBoundingClientRect().top);
|
||||
await row.click();
|
||||
await page.waitForTimeout(400);
|
||||
assert(Math.abs((await row.evaluate((e) => e.getBoundingClientRect().top)) - was) <= 1, "picking the request moved the page");
|
||||
let got = await steps();
|
||||
// the vendor's words as they were, without magpie's hint in them
|
||||
assert.deepEqual(got.filter(([c]) => c === "aside said").map(([, s]) => s), [want[lang].said]);
|
||||
// and the hint on its own line, in the page's language
|
||||
assert.deepEqual(got.filter(([, s]) => s === want[lang].hint).map(([c]) => c), ["aside"]);
|
||||
|
||||
// another 405 gets no hint
|
||||
await page.locator(".rt-req").nth(1).click();
|
||||
await page.waitForTimeout(300);
|
||||
got = await steps();
|
||||
assert.equal(got.filter(([c]) => c === "aside said").length, 1);
|
||||
assert(!got.some(([, s]) => s.includes("Start Plan") || s.includes("体验套餐")), JSON.stringify(got));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -194,6 +194,11 @@ func (p Provider) Explain(msg string, status int, body []byte) string {
|
||||
return msg
|
||||
}
|
||||
if more := p.Account.explain(status, body); more != "" {
|
||||
// an account's reading of a block page that names the network
|
||||
// block itself (ZCodeStartBlockedHint) takes the generic one's place
|
||||
if more == ZCodeStartBlockedHint {
|
||||
msg = strings.TrimSuffix(msg, " — "+BlockedHint)
|
||||
}
|
||||
return msg + " — " + more
|
||||
}
|
||||
return msg
|
||||
|
||||
@@ -328,7 +328,7 @@ var edgeBlocked = regexp.MustCompile(`(?i)request has been blocked|errors\.aliyu
|
||||
// EdgeBlocked says whether an error body is a firewall's block page rather
|
||||
// than the vendor's API answering, or one already put in plain words.
|
||||
func EdgeBlocked(b []byte) bool {
|
||||
return edgeBlocked.Match(b) || bytes.Contains(b, []byte(BlockedHint))
|
||||
return edgeBlocked.Match(b) || bytes.Contains(b, []byte(BlockedHint)) || bytes.Contains(b, []byte(ZCodeStartBlockedHint))
|
||||
}
|
||||
|
||||
// APIError pulls the human message out of an error body when there is one.
|
||||
|
||||
@@ -320,6 +320,12 @@ func zcodeProvider(who, plan string, k zcodeKey) Provider {
|
||||
req.Header.Set("Authorization", "Bearer "+key)
|
||||
return nil
|
||||
}
|
||||
acct.explain = func(status int, body []byte) string {
|
||||
if zcodeOnStart(nil, k) {
|
||||
return zcodeStartExplain(status, body)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
acct.models = func() []catalog.Model {
|
||||
if zcodeOnStart(nil, k) {
|
||||
return zcodeStartModels
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// zcodeBlockPage is the page zcode.z.ai answers a Start Plan request it
|
||||
// turns away with (#425).
|
||||
const zcodeBlockPage = `<!DOCTYPE html><html><head><title>405</title></head><body>
|
||||
<h1>Sorry, your request has been blocked due to unusual activity.</h1>
|
||||
<a href="https://errors.aliyun.com/error/405?code=blocked">errors.aliyun.com</a></body></html>`
|
||||
|
||||
// The Start Plan's block is said for what it is (#425): ZCode turns away
|
||||
// requests that aren't its app's own, or the network blocked the address,
|
||||
// and what to use instead; not only the firewall. A Coding Plan account,
|
||||
// and any other provider, keep the generic hint.
|
||||
func TestZCodeStartBlockedSaid(t *testing.T) {
|
||||
say := func(p Provider, status int, body string) string {
|
||||
return p.Explain(p.Name+": "+APIError([]byte(body), "405 Method Not Allowed"), status, []byte(body))
|
||||
}
|
||||
start := zcodeProvider("trial@example.com", "Start Plan", zcodeKey{JWT: "a.b.c"})
|
||||
if got, want := say(start, http.StatusMethodNotAllowed, zcodeBlockPage), "ZCode: 405 Method Not Allowed — "+ZCodeStartBlockedHint; got != want {
|
||||
t.Fatalf("Start Plan block:\n got %q\nwant %q", got, want)
|
||||
}
|
||||
if got := say(start, http.StatusMethodNotAllowed, `{"code":3012,"msg":"method not allowed"}`); !strings.HasSuffix(got, " — "+ZCodeStartBlockedHint) || strings.Contains(got, BlockedHint) {
|
||||
t.Fatalf("Start Plan 3012: %q", got)
|
||||
}
|
||||
if got := say(start, http.StatusTooManyRequests, `{"code":1302,"msg":"rate limited"}`); strings.Contains(got, ZCodeStartBlockedHint) {
|
||||
t.Fatalf("a rate limit got the block hint: %q", got)
|
||||
}
|
||||
if !EdgeBlocked([]byte(say(start, http.StatusMethodNotAllowed, zcodeBlockPage))) {
|
||||
t.Fatal("the Start Plan's hint, relayed, isn't taken as a block")
|
||||
}
|
||||
|
||||
plan := zcodeProvider("pro@example.com", "GLM Coding Plan", zcodeKey{Key: "id.secret", Base: "https://api.z.ai/api/anthropic"})
|
||||
if got, want := say(plan, http.StatusMethodNotAllowed, zcodeBlockPage), "ZCode: 405 Method Not Allowed — "+BlockedHint; got != want {
|
||||
t.Fatalf("Coding Plan block:\n got %q\nwant %q", got, want)
|
||||
}
|
||||
other := Provider{ID: "za", Name: "ZA"}
|
||||
if got, want := say(other, http.StatusMethodNotAllowed, zcodeBlockPage), "ZA: 405 Method Not Allowed — "+BlockedHint; got != want {
|
||||
t.Fatalf("another provider:\n got %q\nwant %q", got, want)
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -47,6 +48,25 @@ var zcodeStartModels = func() []catalog.Model {
|
||||
return out
|
||||
}()
|
||||
|
||||
// ZCodeStartBlockedHint is what the Start Plan's "request has been blocked
|
||||
// due to unusual activity" (HTTP 405, code 3012 "method not allowed")
|
||||
// means (#425): zcode.z.ai looks at what a request carries and turns away
|
||||
// one that isn't the ZCode app's own, its system prompt and all, as
|
||||
// zcode2api found; it can still be Alibaba Cloud's firewall blocking the
|
||||
// address (BlockedHint). magpie sends the agent's request as it is.
|
||||
const ZCodeStartBlockedHint = "ZCode's Start Plan turns away requests that don't come from the ZCode app itself, and magpie doesn't pretend to be it; it can also be a network block of this IP. Use an account with a GLM Coding Plan, or add another provider to this group"
|
||||
|
||||
// zcodeStartRefused matches that refusal: the block page, or its code.
|
||||
var zcodeStartRefused = regexp.MustCompile(`(?i)unusual activity|"code"\s*:\s*"?3012\b`)
|
||||
|
||||
// zcodeStartExplain gives ZCodeStartBlockedHint for the Start Plan's block.
|
||||
func zcodeStartExplain(status int, body []byte) string {
|
||||
if status >= 400 && (status == http.StatusMethodNotAllowed || EdgeBlocked(body) || zcodeStartRefused.Match(body)) {
|
||||
return ZCodeStartBlockedHint
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ---- which plan -----------------------------------------------------------------
|
||||
|
||||
var zcodeRoutes = struct {
|
||||
|
||||
Reference in New Issue
Block a user