diff --git a/docs/reference.md b/docs/reference.md index 62c61f381..f9b4d5f70 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -1001,8 +1001,13 @@ numbers are kept, and are what its models take once it is serving again. A window is a number agents are shown **and a routing input**: at 95% of the window a request held on a routing-group member moves to one that takes more, so overstating a window makes that move happen too late. A reply limit is -advertised in `/models` and is what a group advertises the smallest of; the -gateway does not itself cap a reply by it. +advertised in `/models` and is what a group advertises the smallest of. The +gateway doesn't lower a limit an agent sends by it. A request that names none +and goes to Anthropic's Messages API, which needs one (Codex's Responses turns, +a Chat client's), is sent it as `max_tokens`, within the window as agents are +told it. Only a model whose limit nobody knows goes at 16384. A reply that +runs into it ends with `stop_reason: max_tokens`, which a Responses client +reads as `incomplete_details.reason: "max_output_tokens"` (#1792). Saving a window or a reply limit writes that number into the model lists magpie keeps in the agents' own files — Pi's `contextWindow` and `maxTokens`, OpenCode's diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index 6934e5341..19f344c2b 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -90,6 +90,7 @@ served by a plugin are in [Provider and plugin ownership](provider-plugins.md). - Claude Code's billing line (`x-anthropic-billing-header: cc_version=…; cc_entrypoint=…; cch=…;`, its own first system block, `cch` changing every turn) goes on only to a Claude model asked on Anthropic's Messages API (`keepsBillingLine` in [`billing_line.go`](../../internal/gateway/billing_line.go): Anthropic's, a relay's, Bedrock's), as Claude Code sent it. Anywhere else it is left out, the rest of the system as sent (`withoutBillingLine`): a vendor's model relayed on Messages (`passthrough`), every translation to Chat, Responses or Gemini (`forwardTranslated`, Claude models too), and the subscriptions asked through their own clients' APIs (Cursor, Devin, Kiro, Qoder, Zed, Command Code's Go plan, in `attempt`). Kept, a vendor read it as the prompt's first words and its prefix cache missed from byte 0 every turn (#1600, justrun1983: 4% read from DeepSeek's cache behind Command Code's plan). The Claude subscription's run sends its own (`withoutBillingHeader`), another magpie decides for the provider it picks, and Code Assist (Antigravity, Gemini CLI) is sent it as before, which `antigravityTurnsAway` reads (#666). - A model that refuses a conversation ending with the assistant's message (`refusesPrefill`: OpenCode Go's Claude models over Messages, "This model does not support assistant message prefill"; Volcengine's Agent Plan, "…for a model that does not support prefill"; Gemini's, "Requests ending with a model turn are not supported") is marked for that provider, model and API (`prefillRefused`, #1447); the provider's other models keep their prefill ([`prefill.go`](../../internal/gateway/prefill.go)). A Chat or Responses client's conversation ending with the assistant's message, which those APIs read as a turn already said (`Request.LastIsTurn`), is asked again with a user turn after it (`continueText`), translated (`forwardTranslated`) or relayed (`passthrough`, `userLastBody`), and so from then on. An Anthropic client's prefill is its own ask and gets the refusal as sent. magpie's own continuation of a cut reply (`continuation.go`) isn't asked of that model again; the try the model refused ends the reply with what cut it, not with the refusal. A request magpie builds in Gemini's own shape (`buildCodeAssistSent`: Vertex AI, Gemini CLI's and Antigravity's Code Assist, Factory) never ends with the model's turn, which all of them turn away: a user turn goes after it, `continueText`, or `compactLastText` when an agent is compacting with its ask in the system prompt (`modelLastAsk`), as one goes before a history that opens with the model's. Nor does it send a user turn that mixes a tool's `functionResponse` with text, which Vertex AI answers with the same "ending with a model turn" (#1533: Codex's compaction prompt after a tool's output): what the user said goes in a user turn of its own after the tools' responses (`hasResponse`), except for a Claude model on Antigravity, whose tool_result turn holds both. - A model's reply limit is published within the window beside it (#1438, `provider.OutputWithin`, `Entry.PublishedOutput`): `/v1/models`' `max_output_tokens` (`modelObject`), Cursor Private Inference's `capabilities.max_output_tokens` (`cursorLocalModel`), Muse Code's `limit.output` (`museModels`), the GUI's model and group rows (`providerInfo`, `providersState`), `magpie model output`, and every agent's file (`agent.maxTokens`, #338). The window and the output can come from different sources: Grok's backend lists grok-4.7's 256000 window, and models.dev fills its 500000 output (`catalog.Decorate` and `Provider.replyLimit` fill an output only where the vendor gives none). An unknown window or output is published as it is. The catalog keeps the unclamped `Entry.Output`, and a group's member is still asked for no more than that (`outputLimit`, `withMaxOutput`), so a request isn't lowered by the clamp. A limit the user set stays in their settings as they set it (`TestModelListsKeepOutputWithinTheWindow`). +- A request that names no reply limit, translated to Anthropic's Messages API, which needs `max_tokens` (`forwardTranslated`; a Zed subscription's Claude in `serveZed`), is sent the model's published limit (`askedOutput` in [`maxoutput.go`](../../internal/gateway/maxoutput.go)): the user's Max output, else the vendor's list or models.dev, within the window. `anthropicBody`'s `defaultMaxTokens` (16384) is left only for a model whose limit isn't known. Every Codex turn on a Claude went at 16384 before, and a long thinking and tool turn ran out of it: `stop_reason: max_tokens` reaches a Responses client as `incomplete_details.reason: "max_output_tokens"` (#1792, tensornull). A limit the client names goes as it is. The thinking budget fits under the filled limit as under one the client named (`TestAnthropicMaxTokensIsTheModels`). ## Remote magpie APIs diff --git a/internal/gateway/anthropic.go b/internal/gateway/anthropic.go index 6fc2a179d..b933798f9 100644 --- a/internal/gateway/anthropic.go +++ b/internal/gateway/anthropic.go @@ -824,7 +824,7 @@ func anthropicBody(r *Request, model string, replay bool) []byte { } maxTokens := r.MaxTokens if maxTokens <= 0 { - maxTokens = 16384 + maxTokens = defaultMaxTokens // the model's own is filled in before (askedOutput) } // a client that turned reasoning off — Codex's or a Chat client's // effort none, which Effort reads as low — is sent thinking off, not a diff --git a/internal/gateway/anthropic_max_tokens_test.go b/internal/gateway/anthropic_max_tokens_test.go new file mode 100644 index 000000000..c348a11e9 --- /dev/null +++ b/internal/gateway/anthropic_max_tokens_test.go @@ -0,0 +1,152 @@ +package gateway + +import ( + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "strings" + "sync" + "testing" + + "github.com/tidwall/gjson" + "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/provider" +) + +// A request that names no reply limit (Codex's Responses turns) is sent on +// Anthropic's API with the model's own: the user's Max output, else the +// vendor's list or models.dev, within the window, as the agents are told it. +// It was sent a flat 16384, which a long thinking and tool turn ran out of +// (#1792, tensornull: "Incomplete response returned, reason: +// max_output_tokens"). 16384 stays for a model whose limit isn't known, and +// a limit the client names goes as it is. +func TestAnthropicMaxTokensIsTheModels(t *testing.T) { + fresh(t) + var mu sync.Mutex + var asked map[string]any + up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var q map[string]any + b, _ := io.ReadAll(r.Body) + json.Unmarshal(b, &q) + mu.Lock() + asked = q + mu.Unlock() + if q["stream"] == true { + w.Header().Set("Content-Type", "text/event-stream") + io.WriteString(w, "event: message_start\ndata: {\"type\":\"message_start\",\"message\":{\"id\":\"m\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[],\"usage\":{\"input_tokens\":1,\"output_tokens\":0}}}\n\n"+ + "event: content_block_start\ndata: {\"type\":\"content_block_start\",\"index\":0,\"content_block\":{\"type\":\"text\",\"text\":\"\"}}\n\n"+ + "event: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"ok\"}}\n\n"+ + "event: content_block_stop\ndata: {\"type\":\"content_block_stop\",\"index\":0}\n\n"+ + "event: message_delta\ndata: {\"type\":\"message_delta\",\"delta\":{\"stop_reason\":\"end_turn\"},\"usage\":{\"output_tokens\":1}}\n\n"+ + "event: message_stop\ndata: {\"type\":\"message_stop\"}\n\n") + return + } + w.Header().Set("Content-Type", "application/json") + io.WriteString(w, `{"id":"m","type":"message","role":"assistant","content":[{"type":"text","text":"ok"}],"stop_reason":"end_turn","usage":{"input_tokens":1,"output_tokens":1}}`) + })) + t.Cleanup(up.Close) + // models.dev's entry for a Claude model, and one listing a reply + // limit past its window + const known, wide = "claude-sonnet-4-5", "wide-1" + os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) + if err := os.WriteFile(catalog.CachePath(), []byte(`{"anthropic":{"id":"anthropic","models":{ + "claude-sonnet-4-5":{"id":"claude-sonnet-4-5","limit":{"context":200000,"output":64000}}, + "wide-1":{"id":"wide-1","limit":{"context":100000,"output":500000}}}}}`), 0o644); err != nil { + t.Fatal(err) + } + catalog.Reset() + t.Cleanup(catalog.Reset) + if err := provider.Save(provider.Provider{ID: "a", Name: "A", Key: "k", Models: []string{"set", known, wide, "mystery-9"}, Anthropic: up.URL + "/v1"}); err != nil { + t.Fatal(err) + } + if err := provider.SetModelOutput("a/set", 65536); err != nil { + t.Fatal(err) + } + s := New() + maxTokens := func(path, body string) (int, map[string]any) { + t.Helper() + mu.Lock() + asked = nil + mu.Unlock() + if code, raw := postJSON(t, s, path, body); code != 200 { + t.Fatalf("%s %s: %d %s", path, body, code, raw) + } + mu.Lock() + defer mu.Unlock() + n, _ := asked["max_tokens"].(float64) + return int(n), asked + } + for _, c := range []struct { + name, path, body string + want int + }{ + {"the user's Max output, Codex's turn", "/v1/responses", `{"model":"a/set","input":"hi"}`, 65536}, + {"the user's Max output, streamed", "/v1/responses", `{"model":"a/set","input":"hi","stream":true}`, 65536}, + {"the user's Max output, a Chat client", "/v1/chat/completions", `{"model":"a/set","messages":[{"role":"user","content":"hi"}]}`, 65536}, + {"models.dev's", "/v1/responses", `{"model":"a/` + known + `","input":"hi"}`, 64000}, + {"models.dev's, within the window", "/v1/responses", `{"model":"a/` + wide + `","input":"hi"}`, 100000}, + {"none known", "/v1/responses", `{"model":"a/mystery-9","input":"hi"}`, defaultMaxTokens}, + {"the client's own", "/v1/responses", `{"model":"a/set","input":"hi","max_output_tokens":1000}`, 1000}, + } { + if got, _ := maxTokens(c.path, c.body); got != c.want { + t.Errorf("%s: max_tokens %d, want %d", c.name, got, c.want) + } + } + + // thinking fits under the model's limit, as under a limit the client + // named: a budget at or past max_tokens is refused with a 400 + if err := provider.SetModelOutput("a/set", 8192); err != nil { + t.Fatal(err) + } + got, q := maxTokens("/v1/responses", `{"model":"a/set","input":"hi","reasoning":{"effort":"high"}}`) + th, _ := q["thinking"].(map[string]any) + budget, _ := th["budget_tokens"].(float64) + if got != 8192 || th["type"] != "enabled" || budget <= 0 || int(budget) >= got { + t.Fatalf("max_tokens %d, thinking %v", got, q["thinking"]) + } +} + +// A Zed subscription's Claude is asked in Anthropic's request inside Zed's +// envelope, so a turn naming no limit takes the model's own there too. +func TestZedClaudeMaxTokensIsTheModels(t *testing.T) { + fresh(t) + var got []int64 + zedUpstream(t, "anthropic", func(w http.ResponseWriter, b []byte, _ string) { + got = append(got, gjson.GetBytes(b, "provider_request.max_tokens").Int()) + zedLines(w, + zedEvent(`{"type":"message_start","message":{"id":"m","role":"assistant","usage":{"input_tokens":1,"output_tokens":0}}}`), + zedEvent(`{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}`), + zedEvent(`{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"ok"}}`), + zedEvent(`{"type":"content_block_stop","index":0}`), + zedEvent(`{"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":1}}`), + zedEvent(`{"type":"message_stop"}`), + zedEnded) + }) + // a provider of the user's stands in for the subscription in the + // catalog ("zed" itself is the built-in's id), saved after zedUpstream + // moves the config folder + if err := provider.Save(provider.Provider{ID: "zz", Name: "Zz", Key: "k", Models: []string{"claude-sonnet-4-5"}, Anthropic: "http://zed.invalid/v1"}); err != nil { + t.Fatal(err) + } + if err := provider.SetModelOutput("zz/claude-sonnet-4-5", 40000); err != nil { + t.Fatal(err) + } + s := New() + for _, body := range []string{ + `{"model":"zz/claude-sonnet-4-5","input":"hi"}`, + `{"model":"zz/claude-sonnet-4-5","input":"hi","max_output_tokens":1000}`, + } { + w := httptest.NewRecorder() + var u Usage + p := provider.Provider{ID: "zz", Account: &provider.Account{Agent: "zed", User: "octo"}} + if status, msg := s.serveZed(w, httptest.NewRequest("POST", "/", strings.NewReader(body)), provider.Responses, p, "claude-sonnet-4-5", []byte(body), &u); status != 200 { + t.Fatalf("%s: %d %q\n%s", body, status, msg, w.Body.String()) + } + } + if len(got) != 2 || got[0] != 40000 || got[1] != 1000 { + t.Fatalf("max_tokens %v, want [40000 1000]", got) + } +} diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index 0d1e9e65c..f360428e7 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -4126,6 +4126,14 @@ func (s *Server) forwardTranslated(ctx context.Context, p provider.Provider, to r := *req r.Tier, req = "priority", &r } + // Anthropic's API needs a reply limit: one the client didn't name + // is the model's own, not a flat 16384 (#1792, askedOutput) + if to == provider.Anthropic && req.MaxTokens <= 0 { + if n := askedOutput(p, model); n > 0 { + r := *req + r.MaxTokens, req = n, &r + } + } wire := provider.UpstreamNameIn(wires, p.ID, model) sent := req if dropsBillingLine(p, to, model, wire) && billingHeader.MatchString(req.System) { diff --git a/internal/gateway/maxoutput.go b/internal/gateway/maxoutput.go index ed776c974..f56abf22c 100644 --- a/internal/gateway/maxoutput.go +++ b/internal/gateway/maxoutput.go @@ -18,6 +18,26 @@ func outputLimit(p provider.Provider, model string) int { return 0 } +// askedOutput is the reply limit a request that names none is sent on +// Anthropic's Messages API, which needs one: the model's own as the agents +// are told it (the user's Max output, else the vendor's list or +// models.dev, within the window), or 0 when none is known. A Codex turn +// names none, and was sent a flat 16384, which a long thinking and tool +// turn ran out of, Codex showing "Incomplete response returned, reason: +// max_output_tokens" (#1792, tensornull). +func askedOutput(p provider.Provider, model string) int { + for _, e := range provider.Served() { + if e.Group == "" && e.Provider.ID == p.ID && (e.Model == model || e.ID == model) { + return e.PublishedOutput() + } + } + return 0 +} + +// defaultMaxTokens is what a request naming no reply limit is sent on +// Anthropic's API for a model whose limit isn't known. +const defaultMaxTokens = 16384 + // withMaxOutput is body, in proto's words, asking for a reply of at most // limit tokens: a request that asks for more is lowered to limit, and // Anthropic's thinking budget, which must be under it, with it. A request diff --git a/internal/gateway/zed.go b/internal/gateway/zed.go index 665d21b26..00958dfa2 100644 --- a/internal/gateway/zed.go +++ b/internal/gateway/zed.go @@ -48,6 +48,12 @@ func (s *Server) serveZed(w http.ResponseWriter, r *http.Request, from provider. // the vendor's own API is told the answer's format in words req = req.inSystem() req.Model = model + // a Claude model's request is Anthropic's, which needs a reply limit: + // one the client didn't name is the model's own, as the Zed editor + // sends it (#1792, askedOutput) + if req.MaxTokens <= 0 && zed.Wire(zedProviderOf(p.Account.User, model)) == "anthropic" { + req.MaxTokens = askedOutput(p, model) + } ask := s.askZed(p.Account.User, model) if req.WebSearch && !searching(r.Context()) { if canSearch() { diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 387a004b2..5d4d4fe9b 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -9584,7 +9584,7 @@ function outputField() { light(); const wrap = el("div", "cxfield"); wrap.append(ox, row); - return field(t("Max output"), wrap, t("The most a reply may hold, told to the agents as their max tokens; empty leaves it to the vendor and models.dev")); + return field(t("Max output"), wrap, t("The most a reply may hold, told to the agents as their max tokens and sent as max_tokens on Anthropic's API when the agent names none; empty leaves it to the vendor and models.dev")); } // compactField is the editor's Compact at (#876): where Codex and Claude diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 81e5ab840..a25f2a1c4 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1243,7 +1243,7 @@ const I18N = { "Context window: {v} is not a length like 128k or 1m": "上下文窗口:{v} 不是 128k、1m 这样的长度", "Max output": "最大输出", "e.g. 32k · or gpt-6=128k, comma separated": "如 32k · 或 gpt-6=128k,逗号分隔", - "The most a reply may hold, told to the agents as their max tokens; empty leaves it to the vendor and models.dev": "单次回复的最大 token 数,作为 max tokens 告知 Agent;留空则按厂商和 models.dev", + "The most a reply may hold, told to the agents as their max tokens and sent as max_tokens on Anthropic's API when the agent names none; empty leaves it to the vendor and models.dev": "单次回复的最大 token 数,作为 max tokens 告知 Agent,Agent 没给时也作为 max_tokens 发给 Anthropic 的 API;留空则按厂商和 models.dev", "Max output: {v} is not a number of tokens like 32k": "最大输出:{v} 不是 32k 这样的 token 数", "Compact at": "压缩阈值", "e.g. 500k · or deepseek-v4-flash=272k, comma separated": "如 500k · 或 deepseek-v4-flash=272k,逗号分隔", @@ -5628,7 +5628,7 @@ const I18N = { "Context window: {v} is not a length like 128k or 1m": "上下文視窗:{v} 不是 128k、1m 這樣的長度", "Max output": "最大輸出", "e.g. 32k · or gpt-6=128k, comma separated": "如 32k · 或 gpt-6=128k,逗號分隔", - "The most a reply may hold, told to the agents as their max tokens; empty leaves it to the vendor and models.dev": "單次回覆的最大 token 數,作為 max tokens 告知 Agent;留空則按廠商和 models.dev", + "The most a reply may hold, told to the agents as their max tokens and sent as max_tokens on Anthropic's API when the agent names none; empty leaves it to the vendor and models.dev": "單次回覆的最大 token 數,作為 max tokens 告知 Agent,Agent 沒給時也作為 max_tokens 發給 Anthropic 的 API;留空則按廠商和 models.dev", "Max output: {v} is not a number of tokens like 32k": "最大輸出:{v} 不是 32k 這樣的 token 數", "Compact at": "壓縮閾值", "e.g. 500k · or deepseek-v4-flash=272k, comma separated": "如 500k · 或 deepseek-v4-flash=272k,逗號分隔", @@ -9989,7 +9989,7 @@ const I18N = { "Context window: {v} is not a length like 128k or 1m": "コンテキストウィンドウ:{v} は 128k や 1m のような長さではありません", "Max output": "最大出力", "e.g. 32k · or gpt-6=128k, comma separated": "例:32k · または gpt-6=128k(カンマ区切り)", - "The most a reply may hold, told to the agents as their max tokens; empty leaves it to the vendor and models.dev": "1 回の返答の最大トークン数で、max tokens としてエージェントに伝えられます。空欄の場合はベンダーと models.dev に従います", + "The most a reply may hold, told to the agents as their max tokens and sent as max_tokens on Anthropic's API when the agent names none; empty leaves it to the vendor and models.dev": "1 回の返答の最大トークン数で、max tokens としてエージェントに伝えられ、エージェントが指定しない場合は Anthropic の API に max_tokens として送られます。空欄の場合はベンダーと models.dev に従います", "Max output: {v} is not a number of tokens like 32k": "最大出力:{v} は 32k のようなトークン数ではありません", "Compact at": "圧縮しきい値", "e.g. 500k · or deepseek-v4-flash=272k, comma separated": "例:500k · または deepseek-v4-flash=272k(カンマ区切り)", @@ -14369,7 +14369,7 @@ const I18N = { "Context window: {v} is not a length like 128k or 1m": "Kontextfenster: {v} ist keine Länge wie 128k oder 1m", "Max output": "Max. Ausgabe", "e.g. 32k · or gpt-6=128k, comma separated": "z. B. 32k · oder gpt-6=128k, durch Kommas getrennt", - "The most a reply may hold, told to the agents as their max tokens; empty leaves it to the vendor and models.dev": "Höchstzahl an Token einer Antwort, den Agenten als max tokens mitgeteilt; leer überlässt es dem Anbieter und models.dev", + "The most a reply may hold, told to the agents as their max tokens and sent as max_tokens on Anthropic's API when the agent names none; empty leaves it to the vendor and models.dev": "Höchstzahl an Token einer Antwort, den Agenten als max tokens mitgeteilt und an Anthropics API als max_tokens gesendet, wenn der Agent keine nennt; leer überlässt es dem Anbieter und models.dev", "Max output: {v} is not a number of tokens like 32k": "Max. Ausgabe: {v} ist keine Token-Zahl wie 32k", "Compact at": "Komprimieren ab", "e.g. 500k · or deepseek-v4-flash=272k, comma separated": "z. B. 500k · oder deepseek-v4-flash=272k, durch Kommas getrennt", diff --git a/internal/gui/tests/provider-max-output.test.cjs b/internal/gui/tests/provider-max-output.test.cjs index c5a27486c..47eeffb01 100644 --- a/internal/gui/tests/provider-max-output.test.cjs +++ b/internal/gui/tests/provider-max-output.test.cjs @@ -64,4 +64,35 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(errors, []); }); } + + // the hint says the size is also what a turn naming none is sent on + // Anthropic's API as max_tokens (#1792, tensornull: Codex's turns were + // sent a flat 16384), in every language, and fits a narrow window + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + for (const width of [900, 420]) { + test(`${engine} ${lang} ${width}px: the max output hint names max_tokens on Anthropic's API`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" })); + t.after(() => browser.close()); + const page = await (await browser.newContext({ viewport: { width, height: 720 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, [])); + await page.goto("http://magpie.test/?view=providers"); + await page.locator(".row.provider").click(); + const box = page.locator("input.outputs"); + await box.waitFor(); + const hint = await box.evaluate((b) => document.getElementById(b.getAttribute("aria-describedby").split(" ").pop()).textContent); + assert.match(hint, /max_tokens/, hint); + assert.match(hint, /Anthropic/, hint); + if (lang !== "en") assert.doesNotMatch(hint, /sent as max_tokens/, "translated: " + hint); + const over = await box.evaluate((b) => { + const h = document.getElementById(b.getAttribute("aria-describedby").split(" ").pop()); + return h.scrollWidth - h.clientWidth + Math.max(0, document.documentElement.scrollWidth - document.documentElement.clientWidth); + }); + assert.equal(over, 0, "the hint wraps inside the window"); + assert.deepEqual(errors, []); + }); + } + } }