Repository navigation
feat(chat): run an agent when a brand is added, once per brand (Onboarding & Help, 00482) - #2150
Merged
gkhngyk merged 6 commits intoNov 6, 2026
Merged
Conversation
…rding & Help, 00482) A new trigger kind, "When a brand is added" (brand_added). createBrand fires it after the answer has gone (after()), never for the demo brand: each enabled trigger of an active agent on All brands, in a workspace with Chat on and a writable plan, queues one run on the new brand that acts as the agent's owner, only when the owner may use that brand. A claim row per (agent, kind, brand) in chat_agent_trigger_claims, inserted with "on conflict do nothing", keeps it to once. The daily limit, the monthly and own-key caps and the AI limit apply as for any event; the 6-hour cooldown reads the agent's runs on that brand only, so it never holds a new brand and needs no exemption. New agent offers the kind; it needs All brands, and the form and the API say so. Onboarding & Help gets it as its default trigger, on All brands, still Ask me first. Migration 00482 adds the kind to both check constraints and the claim table (RLS, select where the agent and brand are, server writes). Help updated. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
…brand-trigger Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Main brought ansvisor#2146, ansvisor#2148 and ansvisor#2149. help/chat/agents.md's front matter keeps both keyword and synonym lists; approved-articles.json regenerated; schema.sql rebuilt. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
…brand-trigger Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
…brand-trigger # Conflicts: # help/chat/agents.md # web/src/lib/help/approved-articles.json
Collaborator
Author
…brand-trigger # Conflicts: # help/chat/agents.md # supabase/schema.sql # web/src/lib/help/approved-articles.json
Collaborator
Author
|
Merged main in again after #2147: agents.md keeps both keyword sets, schema.sql rebuilt with build-schema.sh (00481 + 00482), approved-articles.json regenerated; Help tests pass. |
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
AGENTS plan #11, Onboarding & Help: this adds the "New brand added" trigger that §3.B row 11 names ("New brand or new member"). #2136 left it out because New agent had no such kind. The owner decided to build it now.
The trigger: "When a brand is added" (
brand_added)createBrand(lib/actions/brand.ts). Once the brand is saved, it callsfireBrandAddedinsideafter(), so the page doesn't wait.createBrand.fireBrandAddedalso skips any brand markedis_demo.readArmedOrgs);activeAgents).readBrandAccess).fireBrandsdoes. Its run then stops before it starts and pauses the agent (owner_role), so an Admin sees Take over.chat_agent_trigger_claimstable: one row per (agent, kind, brand), with "on conflict do nothing" (upsert … ignoreDuplicates). A retry, or two servers firing at once, finds the claim taken and does nothing.brand_addedis an event kind, so it counts against the plan's event runs per day: 2 on a trial, 6 on Starter and Growth, 12 on Enterprise.openAgentRun).queueTriggeredRun'sonBrand).cooldown_untilon the trigger row is written but never read. So a second new brand added minutes later is never held back; a test checks this.fireBrandAddedtakes a driver for callers that want runs to start at once.New agent (
agent-form-triggers.tsx,KINDS)brand_added_scope, 400) when an agent is created, or when a change to its triggers or scope would leave this trigger without All brands. The form shows the refusal on the Brands field.The preset (
presets/onboarding-help.json)[{ "kind": "brand_added" }], which §3.B row 11 supports.Migration
00482_chat_agent_brand_added.sqlbrand_addedtochat_agent_triggers_kind_checkand tochat_agent_runs_trigger_kind_check, keeping every kind 00466 allows (agentincluded).chat_agent_trigger_claims:agent_id,kind(brand_addedonly),brand_id,trigger_id(set null when the trigger is removed),claimed_at;brand_id;schema.sqlis regenerated andtypes/supabase.tsupdated.coverage.jslists the table inSKIPPED: a person never adds the demo brand, and no trigger fires for it.main, and 00481 is feat(chat): let an Admin choose who starts agent work, kept with who changed it and when (AC-011, 00481) #2147 (00481_agent_work.sql). Whichever of feat(chat): let an Admin choose who starts agent work, kept with who changed it and when (AC-011, 00481) #2147 and this PR merges second gets aschema.sqlconflict. Rebuild it withbash supabase/build-schema.sh.Help (
chat/agents.md, ≤150 words per section)approved-articles.jsonis regenerated.Not in this PR
Open question: an agent with no owner, or whose owner left, still queues, and its run then pauses the agent. This matches
fireBrands. Should it be skipped silently instead?Related issue
None. AGENTS plan #11, §3.B row 11 (Drive › Agents › AGENTS-plan.md); CHAT-21 §E (triggers) and §H item 38 (runs act as the owner).
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
00482to the database.cd web && npx vitest run src/lib/chat/agent-triggers.test.ts src/lib/chat/agent-rules.test.ts src/lib/chat/agent-form.test.ts src/lib/chat/agents.test.ts src/lib/actions/brand.test.ts src/lib/chat/schema.test.ts src/lib/chat/agents src/components/chat/agents src/lib/helpcd server && npm test(demo coverage)Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)help/(or no user-visible change) — see help/README.mdChecked locally on cc03aa2, which branched from
main5a8de56.main(e2be79b, #2143) was then merged in with no conflicts, giving be36719, which still merges cleanly into currentmain.web/on cc03aa2:format:checkandtypecheckpass;linthas 0 errors; its 7 warnings were already onmain, and none are in this PR's files;yarn test: 988 of 988 files pass (10,617 tests, 1 skipped);yarn buildpasses with CI's placeholder env.web/after the merge:typecheckpasses, and the help, agents, triggers and schema tests pass (7 files, 236 tests).server/(coverage.js):format:checkandlintpass;npm testpasses 419 of 419 files (5,781 tests, 4 skipped).bash supabase/build-schema.shleavesschema.sqlunchanged.No
skills/changes.Generated by Claude Code