Files
magpie/internal/gui/tests/fixtures/curl
yetone 7597c13237 gui: a curl example pasted into a provider's editor fills it in (@mark_li21 on X)
@mark_li21 asked: 能支持通过curl例子直接导入provider不? A curl example
from a vendor's docs, pasted into a custom provider's Base URL or API key,
now fills in the editor instead of being pasted as text.

curlOf (app.js) is one pure function. It reads the paste the way a shell
would: lines joined by \, cmd's ^ or PowerShell's backtick; curl.exe;
quotes and escapes. From that it takes:

- the API that the URL's endpoint names: /chat/completions is Chat,
  /messages is Anthropic and /responses is Responses;
- the base URL before that endpoint, spelled by respellURL the way the
  editor already wants it;
- the key from Authorization: Bearer, x-api-key or api-key;
- the model in the JSON body.

A key that is only a placeholder ($X, ${X}, %X%, <token>, YOUR_API_KEY)
is not taken. The key box is left empty and focused instead. A new
provider adds the model to its models. A saved provider's picks are left
alone, because adding to an empty list would narrow what it serves. A
preset's editor only takes the key.

A note in the editor says what was filled in. It also points out a
placeholder left in the URL, such as {WorkspaceId}, and a URL with no
known endpoint. Its four strings are translated into zh, zh-TW, ja and
de. Text that isn't curl pastes as before, including several keys at
once.

Found along the way: url.onpaste = fromCurl cancelled every plain paste
into the Base URL, because an on-handler that returns false cancels the
event. The handler is now wrapped. The test fails on the unwrapped one.

Fixtures, in internal/gui/tests/fixtures/curl, are the docs' own bytes:
- OpenAI chat (API reference) and Responses (quickstart);
- Anthropic Messages;
- DeepSeek, Zhipu, Moonshot and OpenRouter quick starts;
- Alibaba Bailian's Windows cmd example (^ and \"-escaped JSON);
- SAP AI Core's PowerShell one-liner (curl.exe, <Deployment_url>);
- Unsloth Studio's PowerShell example, with backtick continuations, as
  its usage panel renders the template. This one is not copied from a
  static doc page.

The doc row is "A pasted curl command" in
docs/subsystems/providers-accounts.md.

Run at 674b6ca28 (origin/main) plus this change:
- provider-curl-paste.test.cjs (new): 10/10. It covers Chromium and
  WebKit; curlOf on every fixture, with LF and CRLF line ends; and the
  editor in en and zh at 900px and 440px. The editor checks are the
  filled form, the focused key, the note's text, plain and many-key
  pastes, the saved body, no sideways scroll, no <select> and no page
  errors.
- Related GUI files, run together with the new one, 112/112:
  gui-de, gui-ja, gui-zh-tw, i18n-keys, key-import, nokey-editor,
  provider-add-gemini, provider-base-api, provider-many-keys,
  provider-many-keys-proxy, provider-url-each-api and vertex-editor.
- Broken by hand, the new test goes red:
  - fromCurl taking nothing: 8 of 10 fail (the editor runs);
  - the endpoint not cut from the base URL: 10 of 10 fail;
  - url.onpaste = fromCurl unwrapped: the plain-paste check fails.
- gofmt -l: none. GOOS=linux and GOOS=windows go vet -tags nogui ./...: ok.
- go test -tags nogui -count=1 -timeout 45m ./... in a sandbox HOME:
  exit 0, 66 packages ok, no FAIL.

Not tried:
- the real app (Wails) on macOS, or WebKitGTK on Linux;
- Windows;
- a pasted command used to reach a real vendor with a real key.
2026-10-16 11:01:24 +08:00
..