Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions frontend/src/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@ const english = {
// the user may not have yet. "Register and get a key" promised the sign-up
// flow; this wording covers both arriving signed in and having to sign up.
"获取 API Key": "Get an API key",
"关于 API Key": "About API keys",
"API Key 是 {provider} 发给你的访问凭证,Agent 用它调用模型": "An API key is the credential {provider} issues to you. Agents use it to call models",
"还没有的话,点「获取 API Key」打开 {provider} 的官方页面,在那里注册并创建": "If you do not have one, \"Get an API key\" opens {provider}'s own page, where you sign up and create it",
// States who bills and stops there. An amount, or a word like "cheap", would
// be a promise about a price only the Provider sets.
"连通测试和 Agent 的每次调用都是真实请求,由 {provider} 按它的价格计费;BootAgent 不收费,也不预估费用": "Connection tests and every call an Agent makes are real requests, billed by {provider} at its prices. BootAgent charges nothing and does not estimate the cost",
"自定义模型名称(可选)": "Custom model name (optional)",
// The connection step's model field. It only decides what the probe requests --
// the configured model is chosen on the next step -- and saying so plainly is
Expand Down
42 changes: 42 additions & 0 deletions frontend/src/pages/ProviderKeyPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,46 @@ describe("ProviderKeyPage", () => {

expect(screen.queryByRole("button", { name: "获取 API Key" })).toBeNull();
});

describe("what a key is, for someone who has never had one", () => {
const withoutKey = (provider: Record<string, unknown> = {}) => ({
...baseState,
status: {
...status,
providers: { ppio: { ...status.providers.ppio, has_key: false, key_management_url: "https://ppio.com/settings/key-management", ...provider } },
} as unknown as StatusResponse,
statusState: "success" as const,
});
const explainer = () => screen.queryByRole("list", { name: "关于 API Key" });

it("says what it is, where it comes from and who charges for it", () => {
state = withoutKey();
render(<MemoryRouter><ProviderKeyPage /></MemoryRouter>);

const lines = [...(explainer()?.children ?? [])].map((line) => line.textContent);
expect(lines).toEqual([
"API Key 是 PPIO 发给你的访问凭证,Agent 用它调用模型",
"还没有的话,点「获取 API Key」打开 PPIO 的官方页面,在那里注册并创建",
// No amount and no promise: the price is the Provider's to state.
"连通测试和 Agent 的每次调用都是真实请求,由 PPIO 按它的价格计费;BootAgent 不收费,也不预估费用",
]);
});

// The second line names a button. Without a published page there is no
// button, and the sentence would send the user looking for one.
it("does not point at a button that is not there", () => {
state = withoutKey({ key_management_url: "", home: "" });
render(<MemoryRouter><ProviderKeyPage /></MemoryRouter>);

expect(explainer()?.children).toHaveLength(2);
expect(explainer()?.textContent).not.toContain("获取 API Key");
});

it("stays out of the way once a key is saved", () => {
state = { ...baseState, status, statusState: "success", hasApiKey: true };
render(<MemoryRouter><ProviderKeyPage /></MemoryRouter>);

expect(explainer()).toBeNull();
});
});
});
16 changes: 14 additions & 2 deletions frontend/src/pages/ProviderKeyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function ProviderKeyPage() {
const apiBaseUrl = providerMeta?.base_url || "";
const providerHasKey = Boolean(providerMeta?.has_key);
const builtInProvider = Boolean(providerMeta && !providerMeta.custom);
const hasKeyPage = Boolean(providerMeta?.key_management_url || providerMeta?.home);
const canProbe = providerHasKey;
const desktop = state.setupKind === "desktop" && state.status
? selectedDesktopApp(state.status, state.selectedAgentIds)
Expand Down Expand Up @@ -163,7 +164,18 @@ export function ProviderKeyPage() {

<div className="provider-form">
{!providerHasKey && builtInProvider ? (
<SecureKeyField value="" onChange={secret.setApiKey} resetKey={state.provider} />
<>
<SecureKeyField value="" onChange={secret.setApiKey} resetKey={state.provider} />
{/* Only for someone without a key yet: they are the one who may not
know what is being asked for, or that the Provider is who bills. */}
<ul className="key-explainer" aria-label={t("关于 API Key")}>
<li>{t("API Key 是 {provider} 发给你的访问凭证,Agent 用它调用模型", { provider: providerMeta?.name ?? "" })}</li>
{hasKeyPage ? (
<li>{t("还没有的话,点「获取 API Key」打开 {provider} 的官方页面,在那里注册并创建", { provider: providerMeta?.name ?? "" })}</li>
) : null}
<li>{t("连通测试和 Agent 的每次调用都是真实请求,由 {provider} 按它的价格计费;BootAgent 不收费,也不预估费用", { provider: providerMeta?.name ?? "" })}</li>
</ul>
</>
) : !providerHasKey ? (
<div className="notice notice-warning">
<span>{t("这个模型服务还没有 Key,先到模型服务页面填写")}</span>
Expand All @@ -178,7 +190,7 @@ export function ProviderKeyPage() {
<strong>{providerMeta?.name}</strong>
<span>{providerMeta?.base_url}</span>
</div>
{providerMeta?.key_management_url || providerMeta?.home ? (
{hasKeyPage ? (
<button className="button button-secondary" type="button" onClick={() => void openRegistration()}>
<ExternalLink size={15} />
{t("获取 API Key")}
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,18 @@
.provider-identity-row strong { font-size: 16px; }
.provider-identity-row span { overflow: hidden; color: var(--text-secondary); font-size: 13px; text-overflow: ellipsis; }

/* Sits directly under the key field it explains, closer than the form's own
gap would put it. */
.key-explainer {
margin: -8px 0 0;
padding-left: 18px;
display: grid;
gap: 4px;
color: var(--text-secondary);
font-size: 12px;
line-height: 1.55;
}

.secure-field {
min-height: 44px;
padding: 0 10px;
Expand Down
Loading