Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/automation_engine.py +230 -2
- web/src/automation/AutomationBuilder.tsx +171 -1
RELEASES.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v14",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "71fd70c",
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v14",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
71fd70c
|
api/automation_engine.py
CHANGED
|
@@ -1266,7 +1266,8 @@ def _ensure_ig_action(flow_raw, table):
|
|
| 1266 |
flow = dict(flow_raw or {}) if isinstance(flow_raw, dict) else {}
|
| 1267 |
actions = [a for a in (flow.get("actions") or []) if isinstance(a, dict)]
|
| 1268 |
if actions and actions[0].get("kind") == "create_record":
|
| 1269 |
-
return _pin_unique(
|
|
|
|
| 1270 |
at = next((i for i, a in enumerate(actions) if a.get("kind") == "create_record"), -1)
|
| 1271 |
if at > 0:
|
| 1272 |
actions.insert(0, actions.pop(at))
|
|
@@ -1285,7 +1286,48 @@ def _ensure_ig_action(flow_raw, table):
|
|
| 1285 |
"values": {"handle": "{{handle}}"}},
|
| 1286 |
})
|
| 1287 |
flow["actions"] = actions
|
| 1288 |
-
return _pin_unique(flow)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1289 |
|
| 1290 |
|
| 1291 |
#: The key the discovery writer really upserts on. `run_discover_instagram` keys candidates on
|
|
@@ -5797,7 +5839,35 @@ def _clean_action_config(kind, cfg, depth, seen, count):
|
|
| 5797 |
max_posts, perr = clean_max_posts(cfg.get("maxPosts"), submitted=False)
|
| 5798 |
if perr:
|
| 5799 |
return None, perr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5800 |
return {"profileField": _s(cfg.get("profileField"), 80).strip(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5801 |
# An unknown tier falls back to `anonymous`, never to the paid rung β a typo must
|
| 5802 |
# not be the thing that starts spending money (the `clean_config` rule, verbatim).
|
| 5803 |
"tier": clean_tier(cfg.get("tier")) or "anonymous",
|
|
@@ -6190,6 +6260,146 @@ def _flow_table(defn):
|
|
| 6190 |
return cfg.get("targetTable") or ((defn.get("trigger") or {}).get("table") or "")
|
| 6191 |
|
| 6192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6193 |
def apply_actions(rt, defn, table_key, row_ids, username="automation", log=print):
|
| 6194 |
"""Walk `flow.actions` for each of `row_ids`, then apply the ENDING. Returns the run counts.
|
| 6195 |
|
|
@@ -6224,6 +6434,12 @@ def apply_actions(rt, defn, table_key, row_ids, username="automation", log=print
|
|
| 6224 |
# automation that never finishes at `MAX_UT_IG_ROWS`. One flush, three upserts.
|
| 6225 |
enrich = {"snaps": [], "posts": [], "psnaps": [], "profiles": 0, "ok": 0, "blocked": 0,
|
| 6226 |
"notes": [], "dry": False}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6227 |
if not table_key:
|
| 6228 |
return counts
|
| 6229 |
table = str(table_key)
|
|
@@ -6306,6 +6522,18 @@ def apply_actions(rt, defn, table_key, row_ids, username="automation", log=print
|
|
| 6306 |
f"{table} β name one on the action, or mark a text column as an "
|
| 6307 |
"Instagram profile")
|
| 6308 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6309 |
handle_raw = str(row.get(pkey, "") or "").strip()
|
| 6310 |
if not handle_raw:
|
| 6311 |
continue # nothing to enrich on this record, not an error
|
|
|
|
| 1266 |
flow = dict(flow_raw or {}) if isinstance(flow_raw, dict) else {}
|
| 1267 |
actions = [a for a in (flow.get("actions") or []) if isinstance(a, dict)]
|
| 1268 |
if actions and actions[0].get("kind") == "create_record":
|
| 1269 |
+
return _pin_unique(_ensure_enrich_step(
|
| 1270 |
+
flow_raw if isinstance(flow_raw, dict) else flow))
|
| 1271 |
at = next((i for i, a in enumerate(actions) if a.get("kind") == "create_record"), -1)
|
| 1272 |
if at > 0:
|
| 1273 |
actions.insert(0, actions.pop(at))
|
|
|
|
| 1286 |
"values": {"handle": "{{handle}}"}},
|
| 1287 |
})
|
| 1288 |
flow["actions"] = actions
|
| 1289 |
+
return _pin_unique(_ensure_enrich_step(flow))
|
| 1290 |
+
|
| 1291 |
+
|
| 1292 |
+
def _ensure_enrich_step(flow_raw):
|
| 1293 |
+
"""β 2026-08-07 (owner ruling) β ENRICH IS STEP 2 ON AN INSTAGRAM SEARCH.
|
| 1294 |
+
|
| 1295 |
+
Owner: *"make it default that this enrichment action is Step 2 always, and under Config of
|
| 1296 |
+
Step 2 β¦ we can have a toggle on or off."* Which is the same shape as step 1's ruling and for
|
| 1297 |
+
the same reason: a search that finds profiles and never reads them has done half a job. The
|
| 1298 |
+
difference is the control β step 1 is permanent because a flow without it discards its
|
| 1299 |
+
results, while this one is permanent because the TOGGLE is how you turn it off. Deleting and
|
| 1300 |
+
disabling would be two ways to say one thing, and only one of them survives a re-save.
|
| 1301 |
+
|
| 1302 |
+
β SEEDED ON, AND ON THE FREE RUNG. `tier: "anonymous"` costs nothing, so a search that gains
|
| 1303 |
+
this step by upgrading does not quietly start spending; switching the Source to the paid
|
| 1304 |
+
provider is an explicit choice a person makes in front of the sentence that names the cost.
|
| 1305 |
+
β THE COOLDOWN IS SEEDED ON TOO (30 days). On a table nobody has enriched it changes nothing β
|
| 1306 |
+
a blank `enriched_at` is never "recent" β and the moment there IS history it stops the flow
|
| 1307 |
+
re-buying the same profile nightly. Off-by-default would make the expensive behaviour the
|
| 1308 |
+
accident.
|
| 1309 |
+
|
| 1310 |
+
β THE EXISTENCE TEST WALKS THE FORKS (`walk_actions`). A person who moved enrichment inside an
|
| 1311 |
+
If/then branch has one; seeding a second at the top level would enrich twice and bill twice,
|
| 1312 |
+
which is the duplication `apply_actions` already paid for once with the pinned step 1.
|
| 1313 |
+
"""
|
| 1314 |
+
flow = dict(flow_raw or {}) if isinstance(flow_raw, dict) else {}
|
| 1315 |
+
actions = [a for a in (flow.get("actions") or []) if isinstance(a, dict)]
|
| 1316 |
+
if any(a.get("kind") == "enrich_instagram" for a in walk_actions(actions)):
|
| 1317 |
+
return flow_raw if isinstance(flow_raw, dict) else flow
|
| 1318 |
+
seeded = list(actions)
|
| 1319 |
+
# Index 1 β after the pinned Create record, because there is nothing to enrich until the
|
| 1320 |
+
# profiles have been written as records. `insert` past the end is a plain append, so a flow
|
| 1321 |
+
# with only step 1 lands this at the end, which IS step 2.
|
| 1322 |
+
seeded.insert(1, {
|
| 1323 |
+
"id": "act_enrich", "kind": "enrich_instagram", "enabled": True, "when": None,
|
| 1324 |
+
"config": {"tier": "anonymous", "noFallback": False, "postMetrics": False,
|
| 1325 |
+
"dryRun": False, "maxPosts": DEFAULT_POSTS_PER_PULL,
|
| 1326 |
+
"fromView": "", "sortField": DEFAULT_ENRICH_SORT, "sortDir": "desc",
|
| 1327 |
+
"limit": DEFAULT_ENRICH_LIMIT, "skipRecent": True,
|
| 1328 |
+
"skipRecentDays": DEFAULT_ENRICH_COOLDOWN_DAYS},
|
| 1329 |
+
})
|
| 1330 |
+
return {**flow, "actions": seeded}
|
| 1331 |
|
| 1332 |
|
| 1333 |
#: The key the discovery writer really upserts on. `run_discover_instagram` keys candidates on
|
|
|
|
| 5839 |
max_posts, perr = clean_max_posts(cfg.get("maxPosts"), submitted=False)
|
| 5840 |
if perr:
|
| 5841 |
return None, perr
|
| 5842 |
+
# β 2026-08-07 (owner ruling) β THE SELECTION, and every key here is OPTIONAL with a
|
| 5843 |
+
# working default. That is D-65's lesson applied ahead of time rather than after: an enrich
|
| 5844 |
+
# action stored before this wave carries none of these, and it must keep saving and keep
|
| 5845 |
+
# running. Absent `fromView` = the whole database; absent `limit` = DEFAULT_ENRICH_LIMIT;
|
| 5846 |
+
# `skipRecent` absent = OFF, because a cooldown nobody asked for silently stops enriching.
|
| 5847 |
+
# β `limit` is CLAMPED here and again in `enrich_selection`. Not belt-and-braces: this door
|
| 5848 |
+
# sees a person's typed number and can refuse politely, while the selection sees whatever
|
| 5849 |
+
# is STORED β including configs written before the cap existed. Clamping only here would
|
| 5850 |
+
# let an old 5000 through at run time.
|
| 5851 |
+
try:
|
| 5852 |
+
e_limit = int(cfg.get("limit") or DEFAULT_ENRICH_LIMIT)
|
| 5853 |
+
except (TypeError, ValueError):
|
| 5854 |
+
return None, "how many records to enrich has to be a number"
|
| 5855 |
+
if e_limit < 1:
|
| 5856 |
+
return None, "an enrich step has to be allowed at least one record"
|
| 5857 |
+
try:
|
| 5858 |
+
e_days = int(cfg.get("skipRecentDays") or DEFAULT_ENRICH_COOLDOWN_DAYS)
|
| 5859 |
+
except (TypeError, ValueError):
|
| 5860 |
+
return None, "the number of days has to be a number"
|
| 5861 |
return {"profileField": _s(cfg.get("profileField"), 80).strip(),
|
| 5862 |
+
"fromView": _s(cfg.get("fromView"), 80).strip(),
|
| 5863 |
+
"sortField": _s(cfg.get("sortField"), 60).strip() or DEFAULT_ENRICH_SORT,
|
| 5864 |
+
# Anything that is not "asc" is newest-first, so a typo cannot invert the order a
|
| 5865 |
+
# person is spending against β it lands on the documented default instead.
|
| 5866 |
+
"sortDir": "asc" if str(cfg.get("sortDir") or "").strip().lower() == "asc"
|
| 5867 |
+
else "desc",
|
| 5868 |
+
"limit": min(e_limit, MAX_ENRICH_PER_RUN),
|
| 5869 |
+
"skipRecent": bool(cfg.get("skipRecent")),
|
| 5870 |
+
"skipRecentDays": max(1, e_days),
|
| 5871 |
# An unknown tier falls back to `anonymous`, never to the paid rung β a typo must
|
| 5872 |
# not be the thing that starts spending money (the `clean_config` rule, verbatim).
|
| 5873 |
"tier": clean_tier(cfg.get("tier")) or "anonymous",
|
|
|
|
| 6260 |
return cfg.get("targetTable") or ((defn.get("trigger") or {}).get("table") or "")
|
| 6261 |
|
| 6262 |
|
| 6263 |
+
#: β 2026-08-07 (owner ruling) β WHAT ONE ENRICH STEP MAY SPEND IN A SINGLE RUN.
|
| 6264 |
+
#: `limit` is the number the panel offers; this is the ceiling the module enforces whatever the
|
| 6265 |
+
#: panel sends, and it is DISCLOSED when it bites rather than applied as a silent `[:N]`
|
| 6266 |
+
#: ([[no-unverifiable-aggregates]]). 100 profiles is ~4 minutes of vendor pacing on its own.
|
| 6267 |
+
MAX_ENRICH_PER_RUN = 100
|
| 6268 |
+
DEFAULT_ENRICH_LIMIT = 25
|
| 6269 |
+
DEFAULT_ENRICH_COOLDOWN_DAYS = 30
|
| 6270 |
+
#: Which column the selection orders by when nobody has said. `first_found` newest-first is the
|
| 6271 |
+
#: owner's own example ("top N enrichment sorted by date") and the useful default: it enriches what
|
| 6272 |
+
#: discovery just found rather than re-walking the oldest leads in the book.
|
| 6273 |
+
DEFAULT_ENRICH_SORT = "first_found"
|
| 6274 |
+
|
| 6275 |
+
|
| 6276 |
+
def _order_key(value):
|
| 6277 |
+
"""Order one CELL. Numbers numerically, everything else as text.
|
| 6278 |
+
|
| 6279 |
+
β Cells are stored as STRINGS, so `"20872"` and `"9"` compare in the wrong order as text β
|
| 6280 |
+
which on a `followers` sort is not a cosmetic wrong order, it is the wrong 25 accounts getting
|
| 6281 |
+
paid for. Numbers are tried first and text is the fallback, never the other way round.
|
| 6282 |
+
β Dates need no special case: R3 made these columns `date` and they store `YYYY-MM-DD`, where
|
| 6283 |
+
lexicographic order IS chronological order. If that format ever changes, this comment is the
|
| 6284 |
+
thing that was relied on.
|
| 6285 |
+
"""
|
| 6286 |
+
s = str(value if value is not None else "").strip()
|
| 6287 |
+
try:
|
| 6288 |
+
return (0, float(s.replace(",", "")), "")
|
| 6289 |
+
except ValueError:
|
| 6290 |
+
return (1, 0.0, s.lower())
|
| 6291 |
+
|
| 6292 |
+
|
| 6293 |
+
def _days_since(day, today=None):
|
| 6294 |
+
"""Whole days between a `YYYY-MM-DD` stamp and today, or None when it cannot be read.
|
| 6295 |
+
|
| 6296 |
+
β None means UNKNOWN and every caller must treat it as "not measured", never as 0 or as a
|
| 6297 |
+
large number β the cooldown below reads an unreadable stamp as "never enriched", which spends
|
| 6298 |
+
money rather than skipping. That is the right way round: a skipped record is invisible, and a
|
| 6299 |
+
stamp we cannot parse is our bug, not a reason to silently stop enriching somebody's data.
|
| 6300 |
+
"""
|
| 6301 |
+
import datetime as _dt
|
| 6302 |
+
s = str(day or "").strip()[:10]
|
| 6303 |
+
if not s:
|
| 6304 |
+
return None
|
| 6305 |
+
try:
|
| 6306 |
+
d = _dt.date.fromisoformat(s)
|
| 6307 |
+
except ValueError:
|
| 6308 |
+
return None
|
| 6309 |
+
return ((today or _dt.date.today()) - d).days
|
| 6310 |
+
|
| 6311 |
+
|
| 6312 |
+
def enrich_selection(rt, table_key, cfg, profile_key, today=None):
|
| 6313 |
+
"""β 2026-08-07 (owner ruling) β WHICH records this enrich step spends on, in order.
|
| 6314 |
+
|
| 6315 |
+
Returns `(ordered_row_ids, note)`. The note is the honest account of what the selection did
|
| 6316 |
+
and is surfaced in the run summary; `""` means there is nothing worth saying.
|
| 6317 |
+
|
| 6318 |
+
β **`limit` IS A QUOTA OF WORK DONE, NOT A WINDOW OF ROWS EXAMINED**, and that is the owner's
|
| 6319 |
+
ruling in as many words: *"if a user choose to enrich 30 and from that sorted list of 30, 20 is
|
| 6320 |
+
enriched last 30 days, then it goes to next list like this"*. So the walk CONTINUES past every
|
| 6321 |
+
skipped record until 30 have actually been enriched or the list runs out. The naive reading β
|
| 6322 |
+
take the top 30, then filter β would have billed for 10 and reported success, and the number in
|
| 6323 |
+
the box would have meant something different every run depending on how much of the top of the
|
| 6324 |
+
list happened to be fresh. A quota is predictable; a filtered window is not.
|
| 6325 |
+
|
| 6326 |
+
The order of operations, each step narrowing the one above:
|
| 6327 |
+
1. the optional saved VIEW β resolved through `view_filter`, the SAME resolver `enters_view`
|
| 6328 |
+
and `seed_rows` use. A view that has been deleted is a PROBLEM, never an empty tree: an
|
| 6329 |
+
empty tree matches everything, so degrading would turn "enrich my shortlist" into "enrich
|
| 6330 |
+
the entire database", at vendor prices.
|
| 6331 |
+
2. the SORT β the owner's "top N sorted by date", blanks always last in both directions
|
| 6332 |
+
(a blank is unknown, not smallest).
|
| 6333 |
+
3. the COOLDOWN β skip anything enriched within N days, when the toggle is on.
|
| 6334 |
+
4. the QUOTA β stop at `limit`, itself clamped to `MAX_ENRICH_PER_RUN`.
|
| 6335 |
+
|
| 6336 |
+
β A record with a BLANK handle is skipped and never counted against the quota β there is
|
| 6337 |
+
nothing to enrich and it must not consume a slot somebody paid for.
|
| 6338 |
+
"""
|
| 6339 |
+
t = ut_get(rt, str(table_key or ""))
|
| 6340 |
+
if t is None:
|
| 6341 |
+
return [], f"{table_key!r} is not a database in this workspace"
|
| 6342 |
+
rows = dict(t.get("rows") or {})
|
| 6343 |
+
notes = []
|
| 6344 |
+
|
| 6345 |
+
view_id = str(cfg.get("fromView") or "").strip()
|
| 6346 |
+
if view_id:
|
| 6347 |
+
tree, _fields, problem = view_filter(rt, table_key, view_id)
|
| 6348 |
+
if problem:
|
| 6349 |
+
# β REFUSE, do not widen. See the docstring β this is the branch where a quiet
|
| 6350 |
+
# fallback costs real money.
|
| 6351 |
+
return [], f"the enrich step names a view it cannot read β {problem}"
|
| 6352 |
+
rows = {rid: r for rid, r in rows.items() if lane_match(tree, r)}
|
| 6353 |
+
|
| 6354 |
+
sort_field = str(cfg.get("sortField") or DEFAULT_ENRICH_SORT).strip() or DEFAULT_ENRICH_SORT
|
| 6355 |
+
newest_first = str(cfg.get("sortDir") or "desc").strip().lower() != "asc"
|
| 6356 |
+
have = [(rid, r) for rid, r in rows.items() if str(r.get(sort_field) or "").strip()]
|
| 6357 |
+
blank = [(rid, r) for rid, r in rows.items() if not str(r.get(sort_field) or "").strip()]
|
| 6358 |
+
have.sort(key=lambda x: _order_key(x[1].get(sort_field)), reverse=newest_first)
|
| 6359 |
+
blank.sort(key=lambda x: _rid_num(x[0]))
|
| 6360 |
+
ordered = have + blank
|
| 6361 |
+
|
| 6362 |
+
try:
|
| 6363 |
+
quota = int(cfg.get("limit") or DEFAULT_ENRICH_LIMIT)
|
| 6364 |
+
except (TypeError, ValueError):
|
| 6365 |
+
quota = DEFAULT_ENRICH_LIMIT
|
| 6366 |
+
quota = max(1, min(quota, MAX_ENRICH_PER_RUN))
|
| 6367 |
+
if cfg.get("limit") and quota != int(cfg.get("limit") or 0):
|
| 6368 |
+
notes.append(f"the limit was capped at {MAX_ENRICH_PER_RUN} for one run")
|
| 6369 |
+
|
| 6370 |
+
cooling = bool(cfg.get("skipRecent"))
|
| 6371 |
+
try:
|
| 6372 |
+
days = int(cfg.get("skipRecentDays") or DEFAULT_ENRICH_COOLDOWN_DAYS)
|
| 6373 |
+
except (TypeError, ValueError):
|
| 6374 |
+
days = DEFAULT_ENRICH_COOLDOWN_DAYS
|
| 6375 |
+
days = max(1, days)
|
| 6376 |
+
|
| 6377 |
+
picked, cooled, blank_handle = [], 0, 0
|
| 6378 |
+
for rid, r in ordered:
|
| 6379 |
+
if len(picked) >= quota:
|
| 6380 |
+
break
|
| 6381 |
+
if not str(r.get(profile_key) or "").strip():
|
| 6382 |
+
blank_handle += 1
|
| 6383 |
+
continue
|
| 6384 |
+
if cooling:
|
| 6385 |
+
since = _days_since(r.get("enriched_at"), today=today)
|
| 6386 |
+
if since is not None and since < days:
|
| 6387 |
+
cooled += 1
|
| 6388 |
+
continue
|
| 6389 |
+
picked.append(str(rid))
|
| 6390 |
+
|
| 6391 |
+
# β THE HONEST ACCOUNT. "10 enriched" reads as success whether the quota was 10 or 30, so the
|
| 6392 |
+
# run says when it could NOT fill the quota and why β the same disclosure rule `cap_note` and
|
| 6393 |
+
# `run_plain` follow. Silence here would make a shrinking selection invisible.
|
| 6394 |
+
if cooled:
|
| 6395 |
+
notes.append(f"{cooled} skipped as enriched in the last {days} days")
|
| 6396 |
+
if blank_handle:
|
| 6397 |
+
notes.append(f"{blank_handle} skipped with no handle")
|
| 6398 |
+
if len(picked) < quota and (cooled or blank_handle or ordered):
|
| 6399 |
+
notes.append(f"{len(picked)} of the {quota} asked for β the list ran out")
|
| 6400 |
+
return picked, "; ".join(notes)
|
| 6401 |
+
|
| 6402 |
+
|
| 6403 |
def apply_actions(rt, defn, table_key, row_ids, username="automation", log=print):
|
| 6404 |
"""Walk `flow.actions` for each of `row_ids`, then apply the ENDING. Returns the run counts.
|
| 6405 |
|
|
|
|
| 6434 |
# automation that never finishes at `MAX_UT_IG_ROWS`. One flush, three upserts.
|
| 6435 |
enrich = {"snaps": [], "posts": [], "psnaps": [], "profiles": 0, "ok": 0, "blocked": 0,
|
| 6436 |
"notes": [], "dry": False}
|
| 6437 |
+
# β 2026-08-07 β THE SELECTION, RESOLVED ONCE PER ACTION AND NOT ONCE PER RECORD.
|
| 6438 |
+
# `enrich_selection` sorts and scans the whole table; doing that inside the per-record walk
|
| 6439 |
+
# would be O(rowsΒ²) and, worse, would re-answer "which 25 records" every time a record walked
|
| 6440 |
+
# through β so the quota could never be honoured. Keyed by ACTION id, because two enrich steps
|
| 6441 |
+
# in one flow are two independent budgets.
|
| 6442 |
+
enrich_plan = {}
|
| 6443 |
if not table_key:
|
| 6444 |
return counts
|
| 6445 |
table = str(table_key)
|
|
|
|
| 6522 |
f"{table} β name one on the action, or mark a text column as an "
|
| 6523 |
"Instagram profile")
|
| 6524 |
continue
|
| 6525 |
+
# β 2026-08-07 (owner ruling) β IS THIS RECORD IN THIS RUN'S BUDGET?
|
| 6526 |
+
# Resolved once (see `enrich_plan`) and then a membership test. A record outside
|
| 6527 |
+
# the selection is NOT an error and NOT a skip worth logging per row β it is simply
|
| 6528 |
+
# not this run's work, and the selection's own note already accounts for it.
|
| 6529 |
+
aid = str(act.get("id") or "")
|
| 6530 |
+
if aid not in enrich_plan:
|
| 6531 |
+
chosen, sel_note = enrich_selection(rt, table, cfg, pkey)
|
| 6532 |
+
enrich_plan[aid] = set(chosen)
|
| 6533 |
+
if sel_note:
|
| 6534 |
+
enrich["notes"].append(sel_note)
|
| 6535 |
+
if str(rid) not in enrich_plan[aid]:
|
| 6536 |
+
continue
|
| 6537 |
handle_raw = str(row.get(pkey, "") or "").strip()
|
| 6538 |
if not handle_raw:
|
| 6539 |
continue # nothing to enrich on this record, not an error
|
web/src/automation/AutomationBuilder.tsx
CHANGED
|
@@ -513,6 +513,40 @@ export default function AutomationBuilder({
|
|
| 513 |
: null;
|
| 514 |
if (kind === "find_records")
|
| 515 |
return firstTable ? { table: firstTable.key, cond: null, limit: 25 } : null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
if (kind === "group")
|
| 517 |
/*
|
| 518 |
β RE-SEEDED FOR C-FORK, and the old seed would now be REFUSED. It was
|
|
@@ -556,7 +590,14 @@ export default function AutomationBuilder({
|
|
| 556 |
return "Name the trigger's database first β this needs a column to write.";
|
| 557 |
if (kind === "create_record" || kind === "find_records")
|
| 558 |
return "There is no blank database to point at yet.";
|
| 559 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
};
|
| 561 |
|
| 562 |
/**
|
|
@@ -1933,6 +1974,17 @@ function ActionProps({
|
|
| 1933 |
const values = (cfg as { values?: Record<string, string | number> }).values || {};
|
| 1934 |
const target = tables.find((t) => t.key === String((cfg as { table?: string }).table || ""));
|
| 1935 |
const valueFields = action.kind === "create_record" ? target?.fields || [] : walkFields;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1936 |
|
| 1937 |
return (
|
| 1938 |
<>
|
|
@@ -2111,6 +2163,124 @@ function ActionProps({
|
|
| 2111 |
*/}
|
| 2112 |
{action.kind === "enrich_instagram" ? (
|
| 2113 |
<>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2114 |
<div className="auto-field">
|
| 2115 |
<label htmlFor="autox-atier">Source</label>
|
| 2116 |
<select
|
|
|
|
| 513 |
: null;
|
| 514 |
if (kind === "find_records")
|
| 515 |
return firstTable ? { table: firstTable.key, cond: null, limit: 25 } : null;
|
| 516 |
+
/*
|
| 517 |
+
ββ 2026-08-07 (owner report) β THE ENRICH ACTION HAD NO BRANCH HERE, SO IT WAS
|
| 518 |
+
PERMANENTLY UNCLICKABLE. `disabled={!c.ready || busy || !seedFor(c.kind)}` and this
|
| 519 |
+
function's `return null` fallback meant the row rendered faded, labelled "Needs a
|
| 520 |
+
database", with an EMPTY tooltip (`seedBlock` had no sentence for it either). The server
|
| 521 |
+
declared it `ready:true`, its config panel was fully built and its runner was correct β
|
| 522 |
+
one client-side list nobody updated made the whole capability unreachable. Owner:
|
| 523 |
+
*"The enrichment action, says that it needs a database. So I can't even click it and
|
| 524 |
+
assign a database? thats wicked."*
|
| 525 |
+
|
| 526 |
+
β IT TAKES NO TABLE, AND THAT IS WHY THE OLD LABEL WAS ALSO WRONG. Enrichment acts on
|
| 527 |
+
the record WALKING THE FLOW β the flow's own target database β so there is nothing to
|
| 528 |
+
assign per action. `verify_automation`'s seed-coverage check now derives its subject from
|
| 529 |
+
the server catalog, so the NEXT ready action added without a seed goes red instead of
|
| 530 |
+
shipping invisible.
|
| 531 |
+
|
| 532 |
+
The values mirror `clean_action_config`'s defaults exactly. A seed that disagreed with the
|
| 533 |
+
validator is the wave-23 illegal-seed defect (four kinds shipped a red banner and no card).
|
| 534 |
+
*/
|
| 535 |
+
if (kind === "enrich_instagram")
|
| 536 |
+
return {
|
| 537 |
+
tier: "anonymous", noFallback: false, postMetrics: false, dryRun: false, maxPosts: 10,
|
| 538 |
+
fromView: "", sortField: "first_found", sortDir: "desc",
|
| 539 |
+
// β `skipRecent: true` MATCHES `_ensure_enrich_step`'s server seed, deliberately. One
|
| 540 |
+
// control must not have two defaults depending on whether the step was added by hand or
|
| 541 |
+
// seeded onto an Instagram search β that is the split-default class this repo has paid
|
| 542 |
+
// for twice ([[default-must-pass-its-own-guard]]). It also cannot surprise on first use:
|
| 543 |
+
// nothing has an `Enriched at` yet, so the cooldown changes nothing until run two, which
|
| 544 |
+
// is exactly when not re-paying is what you want.
|
| 545 |
+
// β NOT the validator's default. `clean_action_config` reads an ABSENT key as False, so
|
| 546 |
+
// every enrich action stored before today keeps the behaviour it already had β a seed is
|
| 547 |
+
// what a new step starts with, never a rule applied retroactively (D-65).
|
| 548 |
+
limit: 25, skipRecent: true, skipRecentDays: 30,
|
| 549 |
+
};
|
| 550 |
if (kind === "group")
|
| 551 |
/*
|
| 552 |
β RE-SEEDED FOR C-FORK, and the old seed would now be REFUSED. It was
|
|
|
|
| 590 |
return "Name the trigger's database first β this needs a column to write.";
|
| 591 |
if (kind === "create_record" || kind === "find_records")
|
| 592 |
return "There is no blank database to point at yet.";
|
| 593 |
+
/*
|
| 594 |
+
β NOT `""`. An empty string here renders "Needs a database" with NO tooltip β a disabled
|
| 595 |
+
control that will not say why, which is exactly how the enrich action sat unreachable and
|
| 596 |
+
unexplained. A kind that reaches this line is one somebody forgot to seed, so the fallback
|
| 597 |
+
says the true thing rather than the plausible one: the label above claims a database is
|
| 598 |
+
missing, and for a forgotten seed that claim is a guess.
|
| 599 |
+
*/
|
| 600 |
+
return "This action cannot be added yet β it has no starting configuration.";
|
| 601 |
};
|
| 602 |
|
| 603 |
/**
|
|
|
|
| 1974 |
const values = (cfg as { values?: Record<string, string | number> }).values || {};
|
| 1975 |
const target = tables.find((t) => t.key === String((cfg as { table?: string }).table || ""));
|
| 1976 |
const valueFields = action.kind === "create_record" ? target?.fields || [] : walkFields;
|
| 1977 |
+
/**
|
| 1978 |
+
* The saved views of the database the flow's records WALK β the enrich step's optional filter.
|
| 1979 |
+
*
|
| 1980 |
+
* β Read off `walkTable`, never off `target`: `target` is the Create-record action's own
|
| 1981 |
+
* destination and answers a different question, and on an Instagram discovery flow the two are
|
| 1982 |
+
* routinely different tables. Same trap `walkFields` carries its own note about.
|
| 1983 |
+
* β `undefined` is a THIRD STATE and is preserved as one (`UserTable.views` is absent until the
|
| 1984 |
+
* server sends it) β the panel says "no view list was offered" rather than drawing an empty
|
| 1985 |
+
* picker that reads as "this database has no views".
|
| 1986 |
+
*/
|
| 1987 |
+
const walkViews = (tables.find((t) => t.key === walkTable) || null)?.views;
|
| 1988 |
|
| 1989 |
return (
|
| 1990 |
<>
|
|
|
|
| 2163 |
*/}
|
| 2164 |
{action.kind === "enrich_instagram" ? (
|
| 2165 |
<>
|
| 2166 |
+
{/*
|
| 2167 |
+
ββ 2026-08-07 (owner ruling) β WHICH RECORDS THIS STEP SPENDS ON.
|
| 2168 |
+
Owner: *"how many records with what sort, based on a Filtered view or maybe top N
|
| 2169 |
+
enrichment sorted by date"*. Every enrichment is a vendor call, so an enrich step
|
| 2170 |
+
without this panel bills for EVERY record in the database on EVERY run β which is why
|
| 2171 |
+
these controls shipped in the same change as the fix that made the action clickable at
|
| 2172 |
+
all, rather than after it.
|
| 2173 |
+
|
| 2174 |
+
β THE LIMIT IS A QUOTA OF WORK DONE, NOT A WINDOW OF ROWS READ β the owner's own
|
| 2175 |
+
clarification: *"if a user choose to enrich 30 and from that sorted list of 30, 20 is
|
| 2176 |
+
enriched last 30 days, then it goes to next list"*. The server walks PAST every skipped
|
| 2177 |
+
record until the quota is filled, so the number in this box is a cost ceiling that
|
| 2178 |
+
means the same thing every run. `enrich_selection` owns the rule; this panel never
|
| 2179 |
+
re-implements it.
|
| 2180 |
+
*/}
|
| 2181 |
+
<p className="auto-field-label">Records to enrich</p>
|
| 2182 |
+
<div className="auto-field">
|
| 2183 |
+
<label htmlFor="autox-aview">From view</label>
|
| 2184 |
+
<select
|
| 2185 |
+
id="autox-aview"
|
| 2186 |
+
className="auto-input"
|
| 2187 |
+
value={String((cfg as { fromView?: string }).fromView || "")}
|
| 2188 |
+
disabled={busy || !walkViews}
|
| 2189 |
+
onChange={(e) => setCfg({ fromView: e.target.value })}
|
| 2190 |
+
>
|
| 2191 |
+
<option value="">Every record in the database</option>
|
| 2192 |
+
{(walkViews || []).map((v) => (
|
| 2193 |
+
<option key={v.id} value={v.id}>{v.label}</option>
|
| 2194 |
+
))}
|
| 2195 |
+
</select>
|
| 2196 |
+
{/* β ABSENT vs EMPTY, the `UserTable.views` third state. "This server did not offer a
|
| 2197 |
+
view list" is a different fact from "this database has no views", and rendering an
|
| 2198 |
+
empty picker for the first one is the silent-empty defect wave 23 gated. */}
|
| 2199 |
+
{!walkViews ? (
|
| 2200 |
+
<p className="auto-hint">No view list was offered for that database.</p>
|
| 2201 |
+
) : null}
|
| 2202 |
+
</div>
|
| 2203 |
+
<div className="auto-field">
|
| 2204 |
+
<label htmlFor="autox-asort">Sort by</label>
|
| 2205 |
+
<select
|
| 2206 |
+
id="autox-asort"
|
| 2207 |
+
className="auto-input"
|
| 2208 |
+
value={String((cfg as { sortField?: string }).sortField || "first_found")}
|
| 2209 |
+
disabled={busy}
|
| 2210 |
+
onChange={(e) => setCfg({ sortField: e.target.value })}
|
| 2211 |
+
>
|
| 2212 |
+
{walkFields.length === 0 ? (
|
| 2213 |
+
<option value="first_found">First found</option>
|
| 2214 |
+
) : null}
|
| 2215 |
+
{walkFields.map((f) => (
|
| 2216 |
+
<option key={f.key} value={f.key}>{f.label}</option>
|
| 2217 |
+
))}
|
| 2218 |
+
</select>
|
| 2219 |
+
</div>
|
| 2220 |
+
<div className="auto-field">
|
| 2221 |
+
<label htmlFor="autox-asortdir">Order</label>
|
| 2222 |
+
<select
|
| 2223 |
+
id="autox-asortdir"
|
| 2224 |
+
className="auto-input"
|
| 2225 |
+
value={String((cfg as { sortDir?: string }).sortDir || "desc")}
|
| 2226 |
+
disabled={busy}
|
| 2227 |
+
onChange={(e) => setCfg({ sortDir: e.target.value })}
|
| 2228 |
+
>
|
| 2229 |
+
<option value="desc">Newest / highest first</option>
|
| 2230 |
+
<option value="asc">Oldest / lowest first</option>
|
| 2231 |
+
</select>
|
| 2232 |
+
</div>
|
| 2233 |
+
<div className="auto-field">
|
| 2234 |
+
<label htmlFor="autox-alimit">Limit</label>
|
| 2235 |
+
<input
|
| 2236 |
+
id="autox-alimit"
|
| 2237 |
+
className="auto-input"
|
| 2238 |
+
type="number"
|
| 2239 |
+
min={1}
|
| 2240 |
+
max={100}
|
| 2241 |
+
defaultValue={Number((cfg as { limit?: number }).limit || 25)}
|
| 2242 |
+
disabled={busy}
|
| 2243 |
+
// Commits on blur, like `maxPosts` above and for the same reason: "3" on the way to
|
| 2244 |
+
// "30" is a legal number the server would happily store.
|
| 2245 |
+
onBlur={(e) => setCfg({ limit: Number(e.target.value) || 25 })}
|
| 2246 |
+
/>
|
| 2247 |
+
<p className="auto-hint">
|
| 2248 |
+
Records enriched per run, at most 100. Skipped records do not use up the limit —
|
| 2249 |
+
the run keeps going down the list until it has enriched this many.
|
| 2250 |
+
</p>
|
| 2251 |
+
</div>
|
| 2252 |
+
<label className="auto-check">
|
| 2253 |
+
<input
|
| 2254 |
+
type="checkbox"
|
| 2255 |
+
checked={!!(cfg as { skipRecent?: boolean }).skipRecent}
|
| 2256 |
+
disabled={busy}
|
| 2257 |
+
onChange={(e) => setCfg({ skipRecent: e.target.checked })}
|
| 2258 |
+
/>
|
| 2259 |
+
Skip records enriched recently
|
| 2260 |
+
</label>
|
| 2261 |
+
{/* β THE DAYS BOX ONLY EXISTS WHILE THE RULE IS ON. A number that configures nothing is
|
| 2262 |
+
worse than a missing one ([[wrong-parent-not-broken-control]]) β and this one would
|
| 2263 |
+
read as a cost guard that is running while it is switched off. */}
|
| 2264 |
+
{(cfg as { skipRecent?: boolean }).skipRecent ? (
|
| 2265 |
+
<div className="auto-field">
|
| 2266 |
+
<label htmlFor="autox-acool">Enriched within</label>
|
| 2267 |
+
<input
|
| 2268 |
+
id="autox-acool"
|
| 2269 |
+
className="auto-input"
|
| 2270 |
+
type="number"
|
| 2271 |
+
min={1}
|
| 2272 |
+
defaultValue={Number((cfg as { skipRecentDays?: number }).skipRecentDays || 30)}
|
| 2273 |
+
disabled={busy}
|
| 2274 |
+
onBlur={(e) => setCfg({ skipRecentDays: Number(e.target.value) || 30 })}
|
| 2275 |
+
/>
|
| 2276 |
+
<p className="auto-hint">
|
| 2277 |
+
Days. A profile enriched inside this window is passed over, and the run moves on to
|
| 2278 |
+
the next one — so you never pay twice for the same profile, and the history
|
| 2279 |
+
still gains a point once the window closes.
|
| 2280 |
+
</p>
|
| 2281 |
+
</div>
|
| 2282 |
+
) : null}
|
| 2283 |
+
|
| 2284 |
<div className="auto-field">
|
| 2285 |
<label htmlFor="autox-atier">Source</label>
|
| 2286 |
<select
|