Repository navigation
feat(prompts): bulk import prompts and add several at once - #1013
Conversation
The Tracked Prompts page showed only "All Prompts (N)", with no sign of the plan limit or how many slots were left, so users found out at save time. The header now shows "used / limit prompt locations · <plan> plan" with a progress bar and the slots left (amber from 80%, red when full or over). When the limit is reached, Add prompt explains it with Upgrade plan (Starter) or Contact us (Growth / Enterprise) instead of the form. The numbers come from getLocationQuota, the same org-wide prompt-location count the plan-limit guard enforces, so the counter can't promise a slot a save would reject. getPromptsPageData returns it in the page's single round trip. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Moving to Ansvisor from another tool meant adding prompts one at a time, and the Add Prompt dialog closed after each one. Add Prompt now has two tabs: - Single: "Add to list" queues the typed prompt below the form without saving it, keeps the topic and engines, and clears the field for the next one. "Save & add more" saves the list and stays open; "Save N & close" saves and closes. Duplicates are refused when queued. - Bulk import: a one-column .xlsx or .csv of prompts, one per row, with an optional "Prompt" header, read in the browser (read-excel-file). The preview marks each row valid, duplicate (case and whitespace insensitive, against tracked prompts and earlier rows), error, or over the plan limit. Not-imported and error rows can be downloaded. Imported prompts get the dialog's platforms and the brand's location; topic and location are set afterwards with Edit. Both save through importPrompts, which re-checks the rows and writes them with import_prompts (00122): a per-organization advisory lock, the tracked-location count, and inserts in order until the plan cap, so two imports at once still stop at the limit. The saved prompts go for their first run in one analyze-new request. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…panel's Keeps this branch merging cleanly with the Positions panel range change (feature/prompts-positions-panel-range), which edits the import next to them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
#1009 was squash-merged, so this branch now conflicts with
I'll review once it's mergeable. |
# Conflicts: # supabase/schema.sql # web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good overall, thanks. One thing to fix before merge:
Large imports never get their first analysis. The import sends up to 1,000 prompt ids to analyze-new in one request, and the route validates them with a single .in('id', ids). Against production, a PostgREST in filter worked with 300 ids and failed from 400 up. The error is ignored, so the response is newCount: 0 and the toast says the prompts wait for the next run. This only happens on unlimited plans, since Growth caps at 200, but the import allows 1,000. Please chunk the in filters in analyze-new by 100, as prompt-positions does.
Note: [email protected] was published six days ago. It's from the same long-time maintainer, but consider pinning the exact version in package.json.
# Conflicts: # supabase/schema.sql # web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
A bulk import sends up to 1,000 prompt ids to /analyze-new, and one PostgREST `in` filter over that many fails. The error was ignored, so the route answered newCount: 0 and the imported prompts never got their first analysis. Validate and look up results through selectInChunks (100 ids per request), and fail loudly when a lookup errors. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk thanks, both addressed:
I also merged Separate from this PR: the "already analyzed" lookup in |
gkhngyk
left a comment
There was a problem hiding this comment.
Thanks, both addressed. Migration 00122 is applied to production.
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]>
Summary
PROMPT-005. Moving to Ansvisor from another tool meant adding prompts one at a time, and Add Prompt closed after each one. The dialog now has two tabs.
Single: queue several, then save
Bulk import: a one-column file
.xlsxor.csvwith one column of prompts, one per row. A first row titled Prompt is read as the header and is optional; without it, the first column is prompts from row 1. Other columns are ignored, with a note. An info box in the dialog explains this, and a one-column template can be downloaded.read-excel-file(new dependency, MIT, read-only, ~small, loaded on demand). SheetJS was avoided because its npm package is unmaintained with known advisories.The limit and concurrency
importPrompts. It re-checks the rows (text, duplicates, valid locations, plan-allowed engines, the brand's shopping pref), creates any new topics without touching existing ones (the existingcreateTopicsdeletes the brand's topics first, so it isn't used), and calls:import_prompts(migration 00122), aSECURITY INVOKERplpgsql function. It takes a per-organizationpg_advisory_xact_lock, counts the org's tracked locations (org_prompt_location_usage), and inserts rows in order until the next one would exceedmaxPrompts, in the same tracked-location unit as feat(prompts): show tracked prompt usage against the plan limit #1009. Two imports running at once still stop at the limit. I verified this locally with two concurrent calls against a one-slot limit: one inserted, one didn't.analyze-newrequest (newanalyzeNewPrompts;analyzeNewPromptnow delegates to it).Not in this PR
Notes for reviewers
supabase/schema.sqlwill conflict with feat(prompts): add an Improve tab with platform-specific position suggestions #1011 / feat(prompts): send selected Improve suggestions to Action Center #1012, which add migrations 00120/00121. It's a generated file: after merging either, re-runbash supabase/build-schema.sh. The migration is numbered 00122 to avoid colliding with them.Related issue
None. Product task PROMPT-005 ("Bulk import prompts from Excel / CSV"), adjusted with product (Cihan) to a one-column file plus a multi-add Single tab.
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
.xlsxor.csv(with or without aPromptheader, including a repeated row and an already-tracked prompt). Duplicates are marked, and Import adds the rest with no topic and the brand's location.NEXT_PUBLIC_IS_CLOUD=trueand a lowmaxPrompts, import a longer file: only the first rows that fit are imported, the warning and the not-imported download appear, and usage stops exactly at the limit.All of the above was tested locally (light and dark mode); the test rows were removed afterwards.
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)yarn test(485, including 13 new inlib/prompt-import.test.ts) andyarn build(CI placeholder env) pass. Server checks are unchanged and pass.bash supabase/build-schema.shleavesschema.sqlunchanged.🤖 Generated with Claude Code