Repository navigation
feat(prompts): show usage cards above the tracked prompts table - #1054
Merged
Merged
Conversation
Paused prompts don't run, so they no longer take room on the plan (org_prompt_location_usage now filters on is_active, 00128). Resuming a paused prompt brings its locations back, so it is metered like adding them: setPromptActive refuses with a plan_limit value when there is no room. That closes the pause, add new prompts, resume the old ones way past the limit. Location edits on paused prompts cost nothing until the prompt is resumed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sh safe Second review pass on the active-only prompt quota: - the edit dialog shows a plain message for non-plan failures instead of the raw database error; - setPromptActive returns a failed limit check as a value (ansvisor#427) instead of throwing; - the brand Prompts page keeps its last quota when the refresh after a toggle fails, so the location pickers don't become uncapped; - the prompt-usage doc no longer says paused prompts count; - tests for a missing prompt, a failed limit check, and location edits on paused vs active prompts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolves the conflicts with the bulk import (ansvisor#1013): prompt.ts keeps both setPromptActive and importPrompts, and the Prompts page imports both. The import RPC (00122) counts locations through org_prompt_location_usage, which 00128 limits to active prompts, so imports follow the same count. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cards PROMPT-012 part 1: the data behind the usage cards, read without counting the prompts table on a page view. - Migration 00139 adds prompt_usage_counters, one row per brand (active, paused, active prompt locations). Statement-level triggers on prompts and prompt_sets rebuild the affected brands in the same transaction, under a per-brand advisory lock. prompt_usage_actual() is the one place the counts are computed; it backs the rebuild, the backfill and the nightly check. - prompt_usage_summary(brand) returns the brand's counts and its account's totals from the counter rows only (security invoker). - Indexes on prompts.prompt_set_id and prompt_sets.brand_id, which the rebuild needs and neither had. - GET /api/prompts/usage?brandId= returns the summary with the plan's location limit and call to action. - MCP tool get_prompt_usage and its REST mirror /api/mcp/prompt-usage. - The daily run checks the counters against prompts, rebuilds any that drifted and logs them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PROMPT-012 part 2: the one-line "used / limit prompt locations" meter
becomes a usage block with two groups and five cards.
- This brand: Active prompts and Total prompts. Clicking them filters the
table (Active by default, Paused from the paused count, All); the table
title follows ("Active prompts (57) · Show all 61").
- Account: Active prompts, Prompt locations (with a bar) and Slots left,
with the plan pill and its call to action (Upgrade to Growth, Upgrade plan
or Contact us). Unlimited plans say so.
- Amber from 90% of the limit, red when full or over (after a downgrade).
- The cards load from GET /api/prompts/usage on their own, so the table
never waits for them; skeletons while loading, dashes and Retry on error.
They refresh after a prompt is added, paused, resumed, edited, deleted,
imported, accepted from suggestions or tracked from fan-outs.
- The Add Prompt dialog and bulk import take the plan limit from the same
response, so the page no longer counts prompts on every view.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
…e-counters # Conflicts: # supabase/schema.sql
…e-counters # Conflicts: # supabase/schema.sql # web/src/types/supabase.ts
…e-cards # Conflicts: # web/messages/en.json # web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx # web/src/lib/actions/prompt.ts
…e-counters # Conflicts: # supabase/schema.sql
…e-counters # Conflicts: # supabase/schema.sql
…e-counters # Conflicts: # supabase/schema.sql
…nto feature/prompt-usage-cards
…e-counters # Conflicts: # supabase/schema.sql
…nto feature/prompt-usage-cards
…e-counters # Conflicts: # supabase/schema.sql
…nto feature/prompt-usage-cards
…e-cards # Conflicts: # supabase/schema.sql
…e-cards # Conflicts: # supabase/schema.sql
gkhngyk
approved these changes
Oct 16, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Thanks, approving. 00139 is applied on production. All 206 brands have a counter row (7,326 locations), and repair_prompt_usage_counters() reports no drift. prompt_usage_summary returns a member's brand and no row for another organization's.
On the tree merged with main, web tests pass (799) and the typecheck, prettier and eslint are clean. The merge with main's late-only filter keeps both filters in the table's memo and reset key. The bulk action bar from #1029 already refreshes the cards, since its pause and resume go through setActiveFor and onChanged, which is reloadAfterChange.
8 of 12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is PROMPT-012 part 2. It replaces the one-line "781 / 1000 prompt locations · Enterprise plan · 219 slots left" meter above the Tracked Prompts table with the usage block from the mockup: a header, then five cards in two groups. The numbers come from
GET /api/prompts/usage(#1053).The block
getPromptUsage):messages/en.json(prompts.usage), including the plan pill.The table
Loading and refresh
No more counting on page view
getPromptsPageDatano longer callsgetLocationQuota, which scannedpromptson every page view. The Add Prompt dialog and bulk import now take the plan limit from the usage response (locationQuotaFromUsage). This was the open point from #1053's review.Review
I ran a code review before opening this. It found 10 things.
Fixed (8):
No change needed: members seeing Plan & usage is fine, since the billing tab is open to every role.
Left for later: the bulk action bar in #1029 reloads the table with
loadData. Whichever of the two merges second should switch it toreloadAfterChange, so bulk pause, resume and delete refresh the cards too.Related issue
None. Product spec: PROMPT-012 (Tracked Prompts usage cards), with the mockup
PROMPT-012-usage-mockup.html. Depends on #1053 and #1034.Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Screenshots
Screenshots will be added in a comment.
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors; the 7 warnings are in code this PR doesn't touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
yarn test: 563/563. New in_usage-cards.test.tsx, which renders the cards:locationQuotaFromUsage;prompt-usage.test.tsis updated for the 90% threshold.yarn build: passed.In the browser on the demo brand (self-hosted):
Plan states: with the usage response stood in by test data in the browser, I checked Starter near the limit, Growth full, Starter over the limit, Enterprise (the mockup's numbers) and the error state, in light and dark mode, at 1440px, 1024px (sidebar collapsed and open) and 768px.
🤖 Generated with Claude Code