00f4d84b8f0e875cf0d42e8bfbce2e41ecb8c796
10
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
2b56b3bc4f |
zcode: name the conversation in x-session-id as a bare UUID, so BigModel's prompt cache hits (#388)
ZCode's client names every request's conversation in x-session-id: a bare UUID, the same on each turn (3.14.3 xst/Tst). BigModel keeps a prompt's cache for the requests that name the same session. The plugin sent none, so a long conversation seldom hit the cache (#387). Every zcode request, on the Start Plan and on Coding Plan or team seats alike, now carries it: - the agent's session (chat.headers' sessionID, which magpie fills) goes as it is when it is a UUID, lower-cased; - any other id (magpie-<hex>, ses_..., sess_...) goes as a stable UUID made from its sha256; - with no session, a UUID made from the device. metadata.user_id's session_id is the same UUID, in dress() and marked(). Reviewed at 48013c0, which addresses all four points of the earlier review (UUID shape, session_id in user_id, rebase onto 0.1.30, no "Closes #387"): - TMPDIR=<scratch> HOME=$(mktemp -d) bun test in packages/zcode: 125 pass, 0 fail. bun scripts/check.mjs zcode passes. Merges cleanly onto main. - With main's index.mjs and the PR's tests: 17 fail (all 7 new session tests, plus the start, userid and dual assertions on the header). - Probe through the plugin's chat.headers and loader fetch, as magpie's host calls them (host.js passes sessionID and sets out.headers before the fetch): magpie-<hex> twice gives the same UUID in the header and in user_id.session_id, and ses_other gives a different UUID. None contains magpie, ses_ or sess_. Not tried: a real BigModel request (the author's hit-rate numbers are the evidence: 3/12 before, 24/24 after through magpie). |
||
|
|
57598ad410 |
zcode 0.1.30: a coding plan's requests name the device in metadata.user_id, as ZCode's do (#387)
wendyeq measured BigModel's GLM Coding Plan through magpie hitting the
prompt cache 1 time in 19 without metadata.user_id and 13 in 16 with it;
the official ZCode on the same account reads 95-98% of input from cache.
The plugin only put user_id on the Start Plan's dressed body; a coding
plan or team request went as the agent sent it, and Pi sends none.
ZCode 3.14.3 (glm/zcode.cjs) sets it on every Anthropic-format request,
not only the Start Plan's: Pst() returns MLs({deviceMid, sessionId}) for
any providerKind "anthropic", and vWr() puts it in
providerOptions.anthropic.metadata.userId for both generateText and
streamText. The value is {"device_id":<machine id>,"account_uuid":"",
"session_id":...}.
Now a coding plan or team request to .../v1/messages gets
metadata.user_id = {"device_id":<sign-in's saved device>,
"account_uuid":"","session_id":""}, the same value dress() puts on the
Start Plan's, when the agent sent no user_id of its own; other metadata
is kept and content-length dropped when the body changed. count_tokens
and non-Messages bodies go as they were. An account known only by a key
(a pasted API key, or a saved state with no device) gets a device id
hashed from the key, so it is the same on every start rather than
anyDevice, which was new per process.
Differences from ZCode, kept on purpose: ZCode overwrites any user_id
and fills session_id with its session (sess_ prefix stripped); this
keeps an agent's own user_id and sends session_id "" as dress() does,
one stable value per account.
Tests: userid.test.mjs (new, 6 tests; 5 red on origin/main's index.mjs,
the count_tokens one passes there as it should). start, toolsearch and
dual tests that pinned coding plan bodies byte for byte now expect the
agent's body plus the device's user_id.
Run at this tree: HOME=$(mktemp -d) bun test -> 2672 pass, 1 skip,
0 fail across 229 files; bun scripts/check.mjs ok.
Not tried: a real BigModel or Z.ai coding plan request, so the cache
hit rate after the change is the reporter's measurement, not mine.
|
||
|
|
2d59003f8e |
zcode: the team seat's request test uses a key of its own
start.test.mjs's "a team seat's request goes as the agent sent it" used
key "team.secret", the same as team-gift.test.mjs. In one bun test
process the two files share index.mjs's routes cache (key + jwt), and
when both jwts were built in the same second the seat test read
team-gift's cached route, skipped the billing/balance read and saw 1
request where it expects 2. That kept publish.yml red since
|
||
|
|
935ddb5b45 |
zcode: a team seat lists the person's gift plans and their -Trial models (#359, #371)
A team seat's ZCode session also reads the person's own gift plans (#359): plansOf no longer returns {start:false, gift:null} for every team seat. A team seat stays on its team plan (its personal plan list is not read), its <model>-Trial entries are listed, its card shows the gift buckets beside the team's windows, and a team seat with no or an expired ZCode session gets the "ZCode gift plans (-Trial models) need ZCode's sign-in" line. Plain models spend the team key; -Trial models go to zcode.z.ai with the ZCode session and no team key or organization header.
Reviewed at 4778e0d (on main
|
||
|
|
28f9cbb3b2 |
zcode 0.1.27: the Start Plan's 405 code 3012 says ZCode's risk control blocked the account, not a network block (#348)
zcode.z.ai answers {"code":3012,"msg":"request has been blocked due to
unusual activity."} with 405. Since 10-24 many accounts get it on every
request, and on several of them ZCode's own app (3.16.3) gets the same 405;
ZCode's support bot calls 3012 platform risk control on the account. The
plugin used to put "though magpie sends it as the ZCode app does; it can
be a network block of this IP" after it, and read that JSON as the edge
firewall's page (EDGE_BLOCKED matched "request has been blocked"), so
ZCode's own words and code were dropped.
Now: ZCode's words with the status and code, then provider
ZCodeRestrictedHint word for word ("ZCode's risk control blocked this
account for unusual activity (code 3012); it rests, and the group's other
providers are used. ..."), which magpie's gateway reads as the account
restricted (2h rest, next member asked) from the next magpie release on.
Only an HTML / errors.aliyun.com block page says the network's address
(provider.BlockedHint's words).
Compared with ZCode 3.16.3's glm/zcode.cjs (downloaded from
cdn-zcode.z.ai, the latest on zcode.z.ai): the Start Plan is sent
unsigned there too (requiresClientRequestSigning is false for
zhipu-account start-plan, off-peak and highspeed; X-Client-Sig/Pow apply
to coding-plan keys on the paas origin), and the headers plugins#348's
curl shows are the plugin's set. No request difference was found that
explains 3012; not tried against a real blocked account.
Run: packages/zcode, Bun 1.4.2, sandbox HOME: 102 pass, 0 fail. The new
start.test.mjs case is red on 0.1.26's index.mjs (1 fail, the 3012
message). bun scripts/check.mjs ok.
|
||
|
|
57ec655a24 |
zcode 0.1.22: a Start Plan request goes with ZCode 3.16.3's headers alone, never the agent's, and without ?beta=true
01huadalang (Discord) gets 405 / "ZCode's Start Plan still turned this request away" again on 0.1.21. #343's check was a curl request to magpie, which carries no agent headers. What reached zcode.z.ai: startHeaders set ZCode's headers on top of the ones it was given and removed only x-api-key, authorization and X-Device-Mid. A plugin provider has no account of its own in magpie's gateway, so a request from Claude Code goes to the plugin with Claude Code's own headers (anthropic-beta claude-code-20250219,..., x-app: cli, x-stainless-*, anthropic-dangerous-direct-browser-access, x-claude-code-session-id) and ?beta=true on the URL (gateway.go claudeCodeHeader, #179). All of that went on to the Start Plan. The retired built-in deleted anthropic-beta, and its accounts never got the Claude Code pass-through. ZCode sends none of these on the Start Plan: its only beta, advanced-tool-use, is for coding plans. Now startHeaders builds a new header set: the body's content-type and ZCode's headers, as ZCode.app 3.16.3 (the current stable, 10-23) sends them in glm/zcode.cjs: - buildZCodeSourceHeadersFromContext: X-Os-Version is os.release() alone (it was "darwin 25.2.0 arm64"), and X-Client-Timezone is "unknown" when there is none. - createModelRequestAttributionHeaders: the new x-zcode-query-source: main_turn. - APP_VERSION goes to 3.16.3 (User-Agent, X-ZCode-App-Version and the app_version query). The Start Plan URL loses its query. Prompt texts, the Start Plan provider entry and ai-sdk/anthropic 3.0.81 are the same in 3.14.3 and 3.16.3 (checked against both bundles). The GLM Coding Plan and team paths are unchanged, and a new test holds that they keep the agent's query and headers. Not established: which header (if any) zcode.z.ai keys on. No Start Plan account was used. A network block of the user's IP is still possible, and the error still says so. Run: bun test in packages/zcode under a temp HOME, 90 pass. The two start.test.mjs header tests fail on 0.1.21's index.mjs (Claude Code's x-app/x-stainless-*/anthropic-beta and the query reach the fake). |
||
|
|
44036e2fcc |
zcode 0.1.21: a Start Plan request sends the agent's system prompt at the end of ZCode's third system block, not as a fourth (#343)
fordlyn's report: on a Start Plan account zcode.z.ai now answers every
request whose system has more than three blocks with 405
{"code":3012,"msg":"request has been blocked due to unusual activity."}.
dress() put ZCode's three cached blocks first and then the agent's own
system texts as blocks 4, 5, ..., so every agent (all of them send a
system prompt) was turned away; only a system-less request passed.
What ZCode does, read from ZCode.app 3.14.3's glm/zcode.cjs
(ContextBuilder.assembleSystemMessages): it sends at most three system
messages, the cli_prefix section, the stable sections, and every dynamic
system section joined with "\n\n" into a third block that starts with
"\n\n". A section added to the builder (addSection) is dynamic by
default, so ZCode's own extra system text lands in the third block.
dress() now does the same: the agent's non-blank text blocks are joined
with "\n\n" after afterEnvironment in the third block, which keeps its
cache mark. The first two blocks stay byte for byte ZCode's, as the
issue's bisect requires. GLM Coding Plan and team requests are not
dressed and are unchanged.
Run: TMPDIR=<scratch> HOME=<scratch>/home bun test (2341 pass, 0 fail);
bun scripts/check.mjs (all ok). The new #343 test in start.test.mjs and
four updated layout tests are red on the old index.mjs (5 of 12 fail).
Not tried against the real API: no Start Plan account at hand. The
reporter's own harness got 200 for this shape (system "x", system plus
tools, 32 KB system, multi-turn).
|
||
|
|
09f946b5e6 |
zcode 0.1.19: a GLM Coding Plan's own resets show on the card, each with its end, a team's say so, and a Start Plan refusal says what to do, as the built-in did
What changed, for parity with magpie's built-in ZCode before it retires:
- Personal resets. The built-in's zcodeQuota read
/api/biz/customer-package-reset/list?targetType=PERSONAL with the plan's
key (zhipuPersonalResets, yetone/magpie#1191) and showed the count, by
window, and each reset's end. The plugin read only the team's list.
codingUsage now reads the personal list alongside the subscription list,
so a Coding Plan card (and a dual gift + Coding Plan card, built on it)
carries resets: {count, byWindow, fiveHour, weekly, until, each}.
- Team resets now carry team: true and each, as zhipuTeamResets set Team.
Both lists are read by one resetsOf: only available ones count, each
{until?, window} sorted soonest first with an endless one last
(sortResetCards), nothing on a failed read or none left.
- Start Plan refusal. A Start Plan answer that is a 405, the block page
("request has been blocked" / errors.aliyun.com) or code 3012 / "unusual
activity" now comes back, same status, as {type:"error", error:{message:
"<vendor's words, or the status for a block page> — <hint>"}}, the hint
word for word magpie's provider.ZCodeStartBlockedHint, as the built-in's
zcodeStartExplain / Provider.Explain put it. The block page's own words
are left out, so magpie's APIError no longer reads it as a network
firewall's (BlockedHint). Coding Plan and team answers are untouched.
- README: the resets and the Start Plan's hint.
What was run:
- usage.test.mjs: a new test with #1191's literal reset list (the
built-in's zhipuResetList) fails on 0.1.18 (no resets); the team test,
now expecting team and each, fails on 0.1.18 too.
- start.test.mjs: the new refusal test fails with the startBlocked line
disabled by hand (block page passed through), passes with it.
- Every packages/zcode test file under a scratch HOME: dual 25, gift 20,
models 1, moved 1, own 6, signin 3, start 11, usage 16 (83 pass).
- bun scripts/check.mjs zcode passes.
Not tried: a real account's reset list or a real Start Plan refusal.
`team` and `each` reach magpie's card from its next release; older magpie
ignores them.
|
||
|
|
baa788b1e4 |
zcode 0.1.15: a Start Plan request says the agent's folder, not magpie's, and leaves out what it doesn't know (#86, Hipple)
The plugin runs in magpie's plugin host, so process.cwd() is magpie's own folder (C:\Users\<user>\.config\magpie on Windows). The Start Plan's "# Environment" section said it as "Primary working directory", with a constant "Is a git repository: no" and magpie's shell, and the model went looking in magpie's folder. Now the folder and the git state are the agent's, as magpie tells the plugin's fetch in x-magpie-work-dir (percent-encoded) and x-magpie-work-git (yes/no) (yetone/magpie, provider.WorkDirHeader). Each line is left out when magpie doesn't tell it (an older magpie, an agent that names no folder, a folder not on this computer). The Shell line is gone: the agent's shell isn't known here. Platform and OS Version stay; they are this computer's, as the X-Os-* headers already say. The headers are taken off before anything is sent, on the coding plan too. Run: bun test in packages/zcode (77 pass), bun scripts/check.mjs zcode. With the old index.mjs the new tests fail (6 fail). One real request through the plugin with the owner's z.ai account (coding plan; its Start Plan balance is empty, so the dressed Start Plan path was not tried against the real service): 200. |
||
|
|
cc57432d16 |
zcode: Start Plan requests go as ZCode's own, with its headers and system prompt (0.1.7) (#5)
ARNO on Discord: the plugin's Start Plan requests were answered 405 / 3012 "blocked due to unusual activity" while his own plugin (Freeflow, provider zcode-start) worked from the same machine. zcode.z.ai serves the plan only to what looks like ZCode's own request: a Start Plan request now carries ZCode's headers and its body is dressed as ZCode's (three cached system blocks, the environment section, the date reminder as the first turn, one cache mark on the last block, metadata.user_id naming the sign-in's device). The prompt texts are magpie's (901fd87e), each matching ARNO's plugin's hash. Coding Plan and team requests are unchanged. The Start Plan is advertised again. |