Skip to content

[Draft] feat(ai-credits-widget): API key tab, key sheet and aiCreditsApi client (Stage 0) - #321

Draft
goodbounties-nanoclaw-agent[bot] wants to merge 1 commit into
mainfrom
patch/aicredits-gateway-stage0
Draft

goodbounties-nanoclaw-agent[bot] wants to merge 1 commit into
mainfrom
patch/aicredits-gateway-stage0

Conversation

@goodbounties-nanoclaw-agent

@goodbounties-nanoclaw-agent goodbounties-nanoclaw-agent Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stage 0 of #319 (tracking: #318; migration of existing signer users: #320). Moves the AI Credits widget from the per-user Antseed Desktop / signer-key model to hosted-gateway API keys. Draft until Stage 1 is unblocked; the production deploy stays held until the real backend exists.

Not in this PR (still to come): Stage 1 (payer address replaces the signer in the purchase path, BLOCKED on the account-id confirmation) and Stage 2 (0.2.0 bump, README/docs, final screenshots). The package version is still 0.1.14. Because of that, dev purchases still encode a signer the UI can no longer create, so purchase flows are only testable after Stage 1.

Agent-assisted: this PR was prepared by an AI agent (gdpatchagent) at the request of @rael. The issue's [DRAFT] marker and assignment are still open, see "Process gates" below.

What changed

  • Tabs: Buy Credits (default) / API Key / History. Set Up tab, signer/authorize/Antseed-download modals, signer persistence, on-chain authorization calls, the History signer filter, Withdraw and Close Channel are deleted, and the "requires a desktop computer" notice is removed.
  • New aiCreditsApi client (types plus a Storybook/dev-only mock): getAccount, createOrTopUpKey, rotateKey, revokeKey, getHistory. The widget only talks to a GoodDollar backend. No gateway management API is called from the browser and there is no management token in frontend code or config. The mock base URL is https://mock-gateway.invalid.
  • API Key tab: AI Credits card ("Used this month" replaces Withdrawable), key card (masked key, Active, base URL, spend-limit bar, reset line, Rotate and Revoke with confirm dialogs, empty state), Refresh Balance kept.
  • "Your API key is ready" bottom sheet (Drawer): full key, copy, warning, Claude Code / Codex & others snippet toggle, "I've saved my key", confirm on dismiss. The full key lives in component memory only, never in storage, logs, analytics or aria-live. Both URL formats sit in one constant marked "confirm with AntSeed".
  • Release safety: with no aiCreditsApi configured, Buy is disabled with an "unavailable" notice and the API Key tab shows "coming soon". apps/ai-credits-web passes none, so nobody can pay real G$ and get a mock key or no key.
  • Copy: new intro, 2-step "What's involved", 3-step Quick summary, FAQs rewritten ("What if I lose my API key?" added; the "unused credits" FAQ is neutral and marked pending policy confirmation). The video and written-guide link are removed with a marked restore spot.
  • Landing page (apps/ai-credits-web): Antseed copy and docs links removed; source=antseed widget-only mode removed (partner-embed consumers are affected).
  • Purchase, bonus and GoodID logic are untouched. Stage 1 leftovers (signerPubKey etc. in adapter types, deep-link exports, payerSession) remain on purpose.

Acceptance criteria (mirrored from #319)

Stage 0 status. Unchecked items belong to Stage 1 or Stage 2, or cannot be proven yet.

  • No remaining signer key / Authorize Credits Management / Antseed Desktop / "requires a desktop computer" in UI strings (Set Up UI and landing copy are gone; the pay-blocked message still references Set Up until Stage 1)
  • Tabs are Buy Credits / API Key / History, Buy Credits is the default
  • Buy, then the one-time key sheet shows key, base URL and snippet (both toggle variants); not retrievable afterwards, never in storage / logs / analytics. Sheet and both toggles are covered via the Rotate story; the Buy trigger is untestable until Stage 1.
  • Rotate and Revoke work against the mock with confirm dialogs
  • Withdraw and Close Channel are gone (UI, actions, client methods)
  • History has no signer filter
  • Without aiCreditsApi the widget cannot take payment
  • Mock used in Storybook / dev only; base URL comes from the client; no hardcoded base URL
  • Version 0.2.0 and footer bumped (Stage 2); no compat shims; no commented-out code
  • Build, lint, Storybook and Playwright tests pass; 390px and desktop evidence captured (all pass for Stage 0; final run and refreshed evidence follow in Stage 2)

Overlapping open PRs

  • Fix AI credit deposit minimum for zero-balance buyers #275 (deposit minimum for zero-balance buyers) touches the same package. Whichever merges second rebases, and Fix AI credit deposit minimum for zero-balance buyers #275's behaviour must survive Stage 1.
  • feat: add ecosystem widget and shared wallet shell #313 (ecosystem widget) also overlaps. Impact of the full 0.2.0 on feat: add ecosystem widget and shared wallet shell #313:
    • It only imports AiCreditsWidget and the AiCreditsWidgetProps type; it does not use signer/operator types, onPaySuccess.signerPubKey or the /mocked signer mocks, so the ecosystem package should still compile.
    • It passes no aiCreditsApi (via widgetProps['ai-credits']), so the embedded AI Credits shows Buy disabled and API Key "coming soon" until the host supplies one. Ecosystem AI Credits screenshots will change.
    • packages/ai-credits-widget/tests/header-harness.tsx builds a full adapter state/actions stub with removed fields (signerPubKey, signerPrvKey, operatorSignature, operatorConsent*, operatorAddress, currentOperator, withdrawableUsd, signers, derivedSignerAddress, generateSignerKey, selectSigner, discoverSigners, importSignerFromPrivateKey, applyDeepLinkSigner, signOperatorConsent, revokeOperatorConsent, syncOperatorConsentFromChain, withdrawCredits), so it will break on types.
    • hide-header.spec.ts asserts "One-time setup required before buying AI Credits." and the "Set Up" tab, both removed.
    • Textual conflicts are expected in AiCreditsWidget.tsx (header block, SetupGuidanceCard renamed to GuidanceCard), widgetRuntimeContract.ts and apps/ai-credits-web/src/App.tsx.

Verification (agent-run automated checks; no human testing yet)

  • pnpm build 18/18; package ESLint clean; apps/ai-credits-web tsc clean.
  • tests/widgets/ai-credits-widget: 29/29 Playwright.
  • Storybook test-runner (ai-credits stories): 28/28.
  • apps/ai-credits-web landing spec: 5/5 at desktop, and 5/5 at 390px (run in Chromium because WebKit cannot be installed in the sandbox).
  • Evidence screenshots in tests/widgets/ai-credits-widget/test-results/ (new: acw-07, acw-29 to acw-33); 12 stale ones removed.
  • Not run: WebKit mobile project, live wallet purchase flow (blocked until Stage 1 and a real backend), human keyboard-only pass, reference-vs-result screenshots and happy-path video.

Process gates

  • [DRAFT][PLAN] AI Credits widget: move to hosted AntSeed Gateway (API keys) #319 is still titled [DRAFT][PLAN] and unassigned; AGENTS.md says only an assigned [PLAN] without [DRAFT] may be executed. The requester approved the plan and asked for Stage 0 and this draft PR; maintainer confirmation of the title and assignment is requested before this leaves draft.
  • Draft-exit gates from the contribution guidelines (self-test video, reference screenshots, Copilot review, bounty-lead confirmation) are not yet complete.

Notes

  • The commit is created through the Git Data API and shows as unsigned; squash-merge, do not rebase-merge.
  • packages/ai-credits-widget/src/Untitled (tracked, unrelated) is untouched and not in this diff.

🤖 Generated with Claude Code

…and aiCreditsApi client (Stage 0)

Replaces the Antseed Desktop / signer-key setup flow with hosted-gateway API keys:
Buy Credits / API Key / History tabs, rotate and revoke dialogs, a one-time key
sheet, a typed aiCreditsApi client with a Storybook/dev-only mock, and rewritten
guide and FAQ copy. The purchase path is unchanged until Stage 1. Refs #318, #319.

Co-Authored-By: Claude Code <noreply@anthropic.com>

On-Behalf-Of: gdpatchagent[onecli] (yaskkeryodtdijpv)
@@ -0,0 +1,15 @@
/** Removes trailing slashes so a format can append a path without doubling them. */
function withoutTrailingSlash(baseUrl: string): string {
return baseUrl.replace(/\/+$/, '')

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The review could not proceed because the required GoodDollar CONTRIBUTING.md was unavailable locally and could not be retrieved with the available tools.

No open issues 🎉

What changed in this PR

Implements Stage 0 of #319/#318, preparing the AI Credits widget for hosted-gateway API keys instead of desktop signer setup. The purchase-account migration remains deferred, and production rollout stays held until the real backend and later stages are ready.

Changes:

  • Adds the typed aiCreditsApi interface, development mock, API Key tab, rotation/revocation dialogs, and one-time key sheet.
  • Removes legacy setup and withdrawal UI, defaults to Buy Credits, and blocks purchases without a configured key service.
  • Updates landing-page copy, widget guidance, Storybook examples, and Playwright coverage.
File Description
tests/​widgets/​ai-credits-widget/​states.spec.ts Replaces setup tests with API-key and purchase-gate coverage.
packages/​ai-credits-widget/​tsup.config.ts Removes the obsolete PNG loader.
packages/​ai-credits-widget/​src/​widgetRuntimeContract.ts Adds the API client prop and updates tabs and actions.
packages/​ai-credits-widget/​src/​useApiKey.ts Adds key-management state, operations, and fulfillment retry.
packages/​ai-credits-widget/​src/​useAiCreditsHistory.ts Removes signer filtering and discovery.
packages/​ai-credits-widget/​src/​signerSignatures.ts Removes withdrawal and channel-close signing helpers.
packages/​ai-credits-widget/​src/​mocked/​index.ts Exports the mock key client.
packages/​ai-credits-widget/​src/​mocked/​chainClient.ts Removes the mock withdrawable-balance read.
packages/​ai-credits-widget/​src/​mocked/​backendClient.ts Removes mock withdrawal and channel-close methods.
packages/​ai-credits-widget/​src/​mocked/​AiCreditsMockWidget.tsx Supplies a stable mock key client.
packages/​ai-credits-widget/​src/​mocked/​aiCreditsApi.ts Adds simulated key management and usage data.
packages/​ai-credits-widget/​src/​index.ts Exports API types and gateway URL formats.
packages/​ai-credits-widget/​src/​element.ts Exposes the API client as a web-component property.
packages/​ai-credits-widget/​src/​components/​shared/​tooltips.tsx Removes the unused information tooltip.
packages/​ai-credits-widget/​src/​components/​shared/​CopyAnnouncement.tsx Adds copy feedback without announcing secret values.
packages/​ai-credits-widget/​src/​components/​shared/​CopyableValueRow.tsx Adds a labelled value row with clipboard support.
packages/​ai-credits-widget/​src/​components/​shared/​constants.ts Deletes withdrawal and channel-close tooltip strings.
packages/​ai-credits-widget/​src/​components/​shared/​AddressView.tsx Deletes the legacy address-copy component.
packages/​ai-credits-widget/​src/​components/​setup/​SignerKeyPanel.tsx Deletes signer generation/import UI.
packages/​ai-credits-widget/​src/​components/​setup/​SetupOnboardingFlow.tsx Deletes desktop and signer onboarding.
packages/​ai-credits-widget/​src/​components/​setup/​HowToUseView.tsx Deletes the old setup walkthrough.
packages/​ai-credits-widget/​src/​components/​setup/​AntseedSignerRow.tsx Deletes the desktop signer screenshot component.
packages/​ai-credits-widget/​src/​components/​setup/​AntseedSetupPanel.tsx Deletes desktop download and CLI setup guidance.
packages/​ai-credits-widget/​src/​components/​manage/​SignerOperatorCard.tsx Deletes signer and operator management UI.
packages/​ai-credits-widget/​src/​components/​manage/​RevokeConsentStep.tsx Deletes operator-consent revocation UI.
packages/​ai-credits-widget/​src/​components/​manage/​CreditsManagementCard.tsx Replaces Withdrawable with monthly usage and removes withdrawal controls.
packages/​ai-credits-widget/​src/​components/​index.ts Updates component exports for guides and API keys.
packages/​ai-credits-widget/​src/​components/​history/​HistoryTab.tsx Removes the signer filter control.
packages/​ai-credits-widget/​src/​components/​guide/​HowToUseView.tsx Adds the three-step API-key guide.
packages/​ai-credits-widget/​src/​components/​guide/​GuidanceCard.tsx Updates introductory guidance and removes the AntSeed link.
packages/​ai-credits-widget/​src/​components/​guide/​FaqView.tsx Rewrites FAQs for API keys and pending refund policy.
packages/​ai-credits-widget/​src/​components/​guide/​BonusHighlight.tsx Moves and renames the existing bonus guidance.
packages/​ai-credits-widget/​src/​components/​buy/​OperatorConsentStep.tsx Deletes the authorization step.
packages/​ai-credits-widget/​src/​components/​buy/​GenerateSignerKeyPanel.tsx Deletes signer-key generation and saving screens.
packages/​ai-credits-widget/​src/​components/​buy/​AmountPicker.tsx Updates the estimated-credit label.
packages/​ai-credits-widget/​src/​components/​apiKey/​ApiKeyReadySheet.tsx Adds one-time key display, snippets, copying, and dismissal confirmation.
packages/​ai-credits-widget/​src/​components/​apiKey/​ApiKeyPanel.tsx Adds key-tab orchestration, confirmations, errors, and refresh.
packages/​ai-credits-widget/​src/​components/​apiKey/​ApiKeyCard.tsx Displays masked keys, spend limits, and key actions.
packages/​ai-credits-widget/​src/​chainClient.ts Removes withdrawable-principal reads.
packages/​ai-credits-widget/​src/​backendTypes.ts Removes withdrawable balance from the account view.
packages/​ai-credits-widget/​src/​backendClient.ts Removes withdrawal/close endpoints and withdrawable aggregation.
packages/​ai-credits-widget/​src/​assets/​assets.d.ts Deletes obsolete PNG import declarations.
packages/​ai-credits-widget/​src/​AiCreditsWidget.tsx Integrates key management, revised navigation, and the purchase gate.
packages/​ai-credits-widget/​src/​aiCreditsApi/​types.ts Defines the backend key-management contract.
packages/​ai-credits-widget/​src/​aiCreditsApi/​gatewayUrlFormats.ts Centralizes provisional tool-specific gateway URL formats.
packages/​ai-credits-widget/​src/​adapter.ts Updates tab routing and removes withdrawal/close actions.
examples/​storybook/​src/​stories/​helpers/​aiCreditsWidgetStories.tsx Replaces legacy fixtures with API-key scenarios.
examples/​storybook/​src/​stories/​ai-credits-widget/​AiCreditsWidgetQA.stories.tsx Adds key-state stories and a rotation interaction.
examples/​storybook/​src/​stories/​ai-credits-widget/​AiCreditsWidget.mdx Updates widget documentation for the gateway model.
apps/​ai-credits-web/​tests/​purchase-only.spec.ts Deletes tests for the removed partner-only mode.
apps/​ai-credits-web/​tests/​landing-page.spec.ts Updates assertions for API-key copy and disclosures.
apps/​ai-credits-web/​src/​App.tsx Revises security copy and removes AntSeed links and widget-only mode.
apps/​ai-credits-web/​index.html Updates the page description for API-key access.

Review effort: Balanced

This branch had an error being deployed

2 failed and 1 inactive deployments
preview-storybook — e95cee10 Deployed Nov 20, 2026 by goodbounties-nanoclaw-agent[bot] via preview #650
preview-ai-credits — e95cee10 Deployed Nov 20, 2026 by goodbounties-nanoclaw-agent[bot] via preview #460
internal — e95cee10 Deployed Nov 20, 2026 by goodbounties-nanoclaw-agent[bot] via authorize-preview #650
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants