mirror of
https://github.com/block/buzz.git
synced 2026-12-01 13:42:45 +00:00
fix(desktop): make OpenAI key re-enterable after first save in card mint dialog (#4140)
Fixes a write-once dead-end in the card mint dialog where a user with an
expired OpenAI key had no way to replace it.
**Source-aware key status (Rust + TypeScript).** `card_mint_key_status`
returns a layer discriminant (`"none" | "global" | "persona" | "agent" |
"process"`) instead of a boolean. A pure `resolve_key_layer()` helper in
`card.rs` owns the classification logic; `card_mint_key_status`
delegates to it, so the production path is under direct test with no
duplicate logic.
**Mint form always reachable.** The key panel replaces the mint form
only for `none` (first-time setup) or when the user explicitly opens the
edit panel (`editingKey`). Keys from agent/persona/process layers show
an inline provenance row on the mint form with a "Why?" affordance;
clicking it shows the read-only redirect in a panel with a Cancel button
that returns to the mint form — never a terminal state.
**Precise auth-error matching.** The 401 handling in `cardMintStore.ts`
matches `startsWith("Card mint failed (HTTP 401 ")` plus the specific
`Incorrect API key` text, so avatar-fetch 401 errors pass through
unchanged.
**Tri-state key status row.** "Using your saved OpenAI key · Update"
renders only when `keyLayer === "global"` (confirmed writable key).
Query pending or errored hides the row without asserting key existence.
**Real tests.** Panel visibility derivations live in
`cardMintKeyUtils.ts`, which `AgentCardMintDialog.tsx` imports directly.
Tests cover all layers including the mint-reachability invariant (Mint
reachable for every resolved layer; only `none` gates setup).
- `card.rs` — new `resolve_key_layer()` pure helper;
`card_mint_key_status` delegates to it; 999 lines (under the 1000-line
ratchet)
- `card/tests.rs` — precedence test calls `resolve_key_layer()` directly
(no test-local closure); adds process-layer and blank-value cases
- `tauriPersonas.ts` — `CardMintKeyLayer` type; updated
`cardMintKeyStatus` signature
- `cardMintKeyUtils.ts` — `showKeyPanel`, `showReadOnlyRow`,
`showCancelButton`, `keyPanelTitle`, and helpers; component imports all
of them
- `AgentCardMintDialog.tsx` — inline provenance rows for all key
sources; key panel only for setup/edit; no unused variables
- `cardMintStore.ts` — precise 401 prefix matching
- `e2eBridge.ts` — `card_mint_key_status` stub returns `"global"` (not
boolean)
- Tests: 3959 JS passing, 2089 Rust passing, `tsc --noEmit` clean
Related: [block/buzz#4406](https://github.com/block/buzz/pull/4406)
---------
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Co-authored-by: npub1ng3jzsaqxdhrfq22dg85j3lpr0zsh3jp7g2h9jyxl59wraayapnsu6kvfg <9a232143a0336e34814a6a0f4947e11bc50bc641f21572c886fd0ae1f7a4e867@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -260,11 +260,32 @@ export type MintedAgentCard = {
|
||||
export const NO_OPENAI_KEY_PREFIX = "NO_OPENAI_KEY:";
|
||||
|
||||
/**
|
||||
* Check whether an OpenAI key would resolve for a card mint of this agent
|
||||
* (same env layering as the mint itself). Never returns the key.
|
||||
* Which env layer resolves the OpenAI key for a card mint of this agent.
|
||||
*
|
||||
* - `"none"` — no key configured anywhere; show the first-time setup panel.
|
||||
* - `"global"` — key comes from global Agent Defaults env; writable from the
|
||||
* dialog via `cardMintSaveOpenaiKey`.
|
||||
* - `"persona"` — key is set on the linked persona; cannot be updated from
|
||||
* the mint dialog (would be shadowed by the higher-priority layer).
|
||||
* - `"agent"` — key is set directly on the agent record; same restriction.
|
||||
* - `"process"` — key comes from the process environment (dev fallback);
|
||||
* same restriction.
|
||||
*/
|
||||
export async function cardMintKeyStatus(id: string): Promise<boolean> {
|
||||
return invokeTauri<boolean>("card_mint_key_status", { id });
|
||||
export type CardMintKeyLayer =
|
||||
| "none"
|
||||
| "global"
|
||||
| "persona"
|
||||
| "agent"
|
||||
| "process";
|
||||
|
||||
/**
|
||||
* Report which env layer resolves the OpenAI key for a card mint of this agent
|
||||
* (same layering as the mint itself). Returns a layer discriminant — never the
|
||||
* key value itself. Use to decide whether to show a writable key input (none /
|
||||
* global) or a read-only redirect (persona / agent / process).
|
||||
*/
|
||||
export async function cardMintKeyStatus(id: string): Promise<CardMintKeyLayer> {
|
||||
return invokeTauri<CardMintKeyLayer>("card_mint_key_status", { id });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user