fsanyoto commited on
Commit
885fb10
Β·
verified Β·
1 Parent(s): 222485d

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "current": "325ac93",
3
  "releases": [
4
  {
5
  "version": "v12",
 
1
  {
2
+ "current": "8c13912",
3
  "releases": [
4
  {
5
  "version": "v12",
VERSION CHANGED
@@ -1 +1 @@
1
- 325ac93
 
1
+ 8c13912
api/automation_engine.py CHANGED
@@ -2296,6 +2296,46 @@ BD_POPULATED_FIELDS = frozenset({
2296
  "full_name", "profile_name", "highlights_count", "id", "fbid", "profile_url"})
2297
  BD_MIN_NARROWING = 1
2298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2299
 
2300
  def predicate_narrows(p):
2301
  """Does ONE predicate narrow the corpus scan? Content field + content op, nothing else."""
@@ -2316,10 +2356,17 @@ def narrowing_refusal(preds):
2316
 
2317
 
2318
  def filter_meta():
2319
- """C4's per-field flags for the Find surface: `[{name, populated, narrowing}]` over the
2320
- same 21 names `BD_FILTER_FIELDS` offers (the 3 PII fields stay structurally absent, R3)."""
 
 
 
 
 
 
2321
  return [{"name": n, "populated": n in BD_POPULATED_FIELDS,
2322
- "narrowing": n in BD_NARROWING_FIELDS} for n in BD_FILTER_FIELDS]
 
2323
 
2324
  CANDIDATE_FIELDS = [
2325
  field_def("handle", "Handle"), field_def("profile_url", "Profile", "url"),
 
2296
  "full_name", "profile_name", "highlights_count", "id", "fbid", "profile_url"})
2297
  BD_MIN_NARROWING = 1
2298
 
2299
+ #: ⭐ WHAT A **FRESH** CONDITION ON A FIELD STARTS AS β€” and it lives HERE, beside the narrowing
2300
+ #: law, because the two drifted apart and the drift cost a user their first automation.
2301
+ #:
2302
+ #: β›” THE SCAR, IN THREE WAVES. Wave 21 fixed a seeded condition the server refused for having no
2303
+ #: value by making a new condition NULLARY (`is_not_null` β€” "this field has any value"), and its
2304
+ #: comment called that "narrowing-in-the-right-direction". Wave 22 then wrote `BD_NARROWING_OPS`
2305
+ #: and `is_not_null` is NOT IN IT, which silently made that default a condition the save door
2306
+ #: always refuses. Wave 24 deleted the create wizard, so the Find panel became the ONLY way in β€”
2307
+ #: and the refusal moved from a corner case to the first thing a new user meets. Three waves, one
2308
+ #: sentence of drift, and nothing red anywhere at any point.
2309
+ #:
2310
+ #: So the rule is now DERIVED and ASSERTED (`verify_automation.py`): a fresh condition on a field
2311
+ #: that CAN narrow must narrow. The client asks for `defaultOperator` per field and never picks
2312
+ #: one itself β€” a client-side default is a second copy of this table, free to disagree with the
2313
+ #: guard that judges it, which is exactly what happened.
2314
+ BD_ARRAY_FIELDS = frozenset({"bio_hashtags", "post_hashtags", "related_accounts"})
2315
+ BD_BOOLEAN_FIELDS = frozenset({"is_business_account", "is_professional_account", "is_verified"})
2316
+ #: Narrowing fields whose values are IDENTIFIERS β€” a substring match on a handle or an id is a
2317
+ #: worse question than an equality, and both narrow.
2318
+ BD_EXACT_FIELDS = frozenset({"account", "id", "fbid", "profile_url"})
2319
+
2320
+
2321
+ def default_operator(name):
2322
+ """The operator a NEW condition on `name` starts with.
2323
+
2324
+ Narrowing wherever the field can narrow, so a fresh condition is ONE step (type a value) from
2325
+ saveable rather than two (change the comparison, then type a value) β€” with the second step
2326
+ being one the surface never told anyone to take.
2327
+ """
2328
+ if name in BD_ARRAY_FIELDS:
2329
+ return "array_includes"
2330
+ if name in BD_EXACT_FIELDS or name in BD_BOOLEAN_FIELDS:
2331
+ return "="
2332
+ if name in BD_NARROWING_FIELDS:
2333
+ return "includes"
2334
+ # Numbers. `>=` cannot narrow the scan and is not pretending to β€” it is the comparison a
2335
+ # person reaching for `followers` means, and the guard's sentence is the honest answer when
2336
+ # it is the ONLY condition present.
2337
+ return ">="
2338
+
2339
 
2340
  def predicate_narrows(p):
2341
  """Does ONE predicate narrow the corpus scan? Content field + content op, nothing else."""
 
2356
 
2357
 
2358
  def filter_meta():
2359
+ """C4's per-field flags for the Find surface: `[{name, populated, narrowing, defaultOperator}]`
2360
+ over the same 21 names `BD_FILTER_FIELDS` offers (the 3 PII fields stay structurally absent,
2361
+ R3).
2362
+
2363
+ `defaultOperator` rides here rather than being a client constant for the reason written over
2364
+ `default_operator`: the client's own default was `is_not_null` for every field, which the
2365
+ narrowing guard refuses on every field.
2366
+ """
2367
  return [{"name": n, "populated": n in BD_POPULATED_FIELDS,
2368
+ "narrowing": n in BD_NARROWING_FIELDS,
2369
+ "defaultOperator": default_operator(n)} for n in BD_FILTER_FIELDS]
2370
 
2371
  CANDIDATE_FIELDS = [
2372
  field_def("handle", "Handle"), field_def("profile_url", "Profile", "url"),
web/src/automation/AutomationDetail.tsx CHANGED
@@ -240,11 +240,24 @@ export default function AutomationDetail({
240
  // --- discover_instagram half (R7)
241
  const [recordsLimit, setRecordsLimit] = useState(Number(cfg.recordsLimit || 25));
242
  const [joinOp, setJoinOp] = useState(String(cfg.operator || "and"));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  const [preds, setPreds] = useState<Predicate[]>(() => {
244
  const stored = (automation.config as { predicates?: Predicate[] })?.predicates;
245
- return stored && stored.length
246
- ? stored.map((p) => ({ ...p }))
247
- : [{ name: "followers", operator: ">=", value: 10000 }];
248
  });
249
  const [estimate, setEstimate] = useState<DiscoverEstimate | null>(null);
250
 
@@ -433,6 +446,34 @@ export default function AutomationDetail({
433
  * value for any flag a config omits β€” so a Save from here can never quietly
434
  * turn the paid rung off. (`clean_config`'s `flag()`, asserted in section N.)
435
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  const buildConfig = (): Record<string, unknown> => {
437
  if (kind === "scrape_db") {
438
  const fieldMap: Record<string, string> = {};
@@ -451,7 +492,7 @@ export default function AutomationDetail({
451
  return {
452
  recordsLimit,
453
  operator: joinOp,
454
- predicates: preds.filter((p) => p.name && p.operator),
455
  targetTable: String(cfg.targetTable || ""),
456
  };
457
  }
@@ -489,7 +530,16 @@ export default function AutomationDetail({
489
  schedule: sched || { cron, enabled: !!automation.schedule?.enabled },
490
  });
491
  setTouched(false);
492
- if (announce) setMessage("Saved.");
 
 
 
 
 
 
 
 
 
493
  return res.automation.id;
494
  };
495
 
 
240
  // --- discover_instagram half (R7)
241
  const [recordsLimit, setRecordsLimit] = useState(Number(cfg.recordsLimit || 25));
242
  const [joinOp, setJoinOp] = useState(String(cfg.operator || "and"));
243
+ /**
244
+ * β›” NO SEEDED CONDITION, AND THAT IS THE FIX.
245
+ *
246
+ * This used to seed `{followers >= 10000}` when nothing was stored β€” a field the narrowing
247
+ * guard does not count and a comparison it does not count either. Every Save of a discovery
248
+ * automation therefore sent it and 400'd with "add at least one CONTENT condition…": renaming
249
+ * the automation, changing the cron, editing a step, all of it, on an automation whose filter
250
+ * the user had never touched. Wave 24 made it unmissable by deleting the wizard, so this seed
251
+ * became what every new Instagram automation carries from birth.
252
+ *
253
+ * ⚠ EMPTY IS LEGAL AND MEANS SOMETHING. `clean_predicates` stores `[]` inert (wave 24 A2) and
254
+ * `configured: false` rides the wire, so the surface says "finish setting this up" instead of
255
+ * refusing the save β€” while `run_discover_instagram` still refuses to SPEND on a filter that
256
+ * narrows nothing. Incomplete is a state; only the money door is a wall.
257
+ */
258
  const [preds, setPreds] = useState<Predicate[]>(() => {
259
  const stored = (automation.config as { predicates?: Predicate[] })?.predicates;
260
+ return stored && stored.length ? stored.map((p) => ({ ...p })) : [];
 
 
261
  });
262
  const [estimate, setEstimate] = useState<DiscoverEstimate | null>(null);
263
 
 
446
  * value for any flag a config omits β€” so a Save from here can never quietly
447
  * turn the paid rung off. (`clean_config`'s `flag()`, asserted in section N.)
448
  */
449
+ /**
450
+ * The discovery conditions that are FINISHED enough to send.
451
+ *
452
+ * A condition is written in two gestures β€” pick the comparison, then type the value β€” and the
453
+ * server refuses a non-nullary comparison with no value ("give a value to compare 'biography'
454
+ * against"). Sending a half-written row therefore turned every Save between those two gestures
455
+ * into an error about a condition the user was still in the middle of writing. Held back
456
+ * instead: the row stays on screen and in state, it just is not claimed to the server yet.
457
+ *
458
+ * ⚠ HELD BACK IS SAID OUT LOUD (see `persist`) β€” a row that vanishes from the stored filter
459
+ * without a word is the silent-drop class this module refuses everywhere else.
460
+ *
461
+ * The nullary list comes off the wire; the literal is only for a server that did not send one,
462
+ * and it errs toward SENDING (the server then refuses, loudly) rather than toward dropping.
463
+ */
464
+ const completePreds = (): Predicate[] => {
465
+ const nullary = discover?.nullaryOperators || ["is_null", "is_not_null"];
466
+ return preds.filter((p) => {
467
+ if (!p.name || !p.operator) return false;
468
+ if (nullary.includes(p.operator)) return true;
469
+ return !(
470
+ p.value === undefined ||
471
+ p.value === null ||
472
+ (typeof p.value === "string" && !p.value.trim())
473
+ );
474
+ });
475
+ };
476
+
477
  const buildConfig = (): Record<string, unknown> => {
478
  if (kind === "scrape_db") {
479
  const fieldMap: Record<string, string> = {};
 
492
  return {
493
  recordsLimit,
494
  operator: joinOp,
495
+ predicates: completePreds(),
496
  targetTable: String(cfg.targetTable || ""),
497
  };
498
  }
 
530
  schedule: sched || { cron, enabled: !!automation.schedule?.enabled },
531
  });
532
  setTouched(false);
533
+ if (announce) {
534
+ // The held-back half of `completePreds`, said rather than swallowed.
535
+ const held = kind === "discover_instagram" ? preds.length - completePreds().length : 0;
536
+ setMessage(
537
+ held > 0
538
+ ? `Saved β€” ${held} condition${held === 1 ? " was" : "s were"} not saved yet, `
539
+ + `${held === 1 ? "it needs" : "they need"} a value.`
540
+ : "Saved."
541
+ );
542
+ }
543
  return res.automation.id;
544
  };
545
 
web/src/automation/AutomationFind.tsx CHANGED
@@ -208,23 +208,24 @@ interface FieldRow {
208
  }
209
 
210
  /**
211
- * A default operator that is VALID THE MOMENT THE SWITCH GOES ON.
212
  *
213
- * ⚠ This is the wave-21 item-8 scar in a new shape. A new condition used to
214
- * arrive as `{biography includes ""}` β€” a comparison with no value, which
215
- * `clean_predicates` refuses outright β€” so adding one and pressing Save returned
216
- * "give a value to compare 'biography' against" for a condition the user had not
217
- * finished writing. A NULLARY operator needs no value, so a freshly toggled
218
- * field is a complete, saveable, narrowing-in-the-right-direction condition
219
- * ("this field has any value") from its first frame.
220
  *
221
- * Derived from the server's own lists rather than typed here, so it cannot name
222
- * an operator the API rejects.
 
 
223
  */
224
- function firstOperator(v?: DiscoverVocab): string {
225
- const nullary = v?.nullaryOperators || [];
226
- const preferred = nullary.find((o) => o === "is_not_null");
227
- return preferred || nullary[0] || (v?.operators || [])[0] || "";
228
  }
229
 
230
  /**
@@ -302,7 +303,7 @@ export default function AutomationFind({
302
  onPreds(preds.filter((p) => p.name !== row.name));
303
  return;
304
  }
305
- onPreds([...preds, { name: row.name, operator: firstOperator(discover) }]);
306
  };
307
 
308
  /** One condition line β€” the comparison, its value, and a way out. */
@@ -408,7 +409,7 @@ export default function AutomationFind({
408
  type="button"
409
  className="autob-cond-add"
410
  onClick={() =>
411
- onPreds([...preds, { name: row.name, operator: firstOperator(discover) }])
412
  }
413
  >
414
  Another condition on {row.name}
 
208
  }
209
 
210
  /**
211
+ * The comparison a freshly toggled field starts with β€” ASKED FOR, never chosen here.
212
  *
213
+ * β›” THE THIRD COSTUME OF ONE SCAR, and the reason this function no longer has an opinion.
214
+ * Wave 21 made a new condition NULLARY (`is_not_null`) so it would be saveable without a
215
+ * value, and called that "narrowing-in-the-right-direction". Wave 22 then wrote the narrowing
216
+ * law server-side and `is_not_null` is not in it. From that moment, toggling ANY field on and
217
+ * pressing Save returned "add at least one CONTENT condition…" β€” the error told the user to do
218
+ * the exact thing they had just done. Wave 24 deleted the wizard and made this panel the only
219
+ * door, so it stopped being a corner case and became the first thing a new user hits.
220
  *
221
+ * The fix is not a better guess. It is that the module owning the guard also names the default
222
+ * (`automation_engine.default_operator`, asserted against `predicate_narrows` in
223
+ * `verify_automation.py`), and this file looks it up per FIELD. An absent one falls back to the
224
+ * server's first operator β€” never to a nullary, which is the thing that could not narrow.
225
  */
226
+ function firstOperator(v: DiscoverVocab | undefined, name: string): string {
227
+ const meta = (v?.filterMeta || []).find((m) => m.name === name);
228
+ return meta?.defaultOperator || (v?.operators || [])[0] || "";
 
229
  }
230
 
231
  /**
 
303
  onPreds(preds.filter((p) => p.name !== row.name));
304
  return;
305
  }
306
+ onPreds([...preds, { name: row.name, operator: firstOperator(discover, row.name) }]);
307
  };
308
 
309
  /** One condition line β€” the comparison, its value, and a way out. */
 
409
  type="button"
410
  className="autob-cond-add"
411
  onClick={() =>
412
+ onPreds([...preds, { name: row.name, operator: firstOperator(discover, row.name) }])
413
  }
414
  >
415
  Another condition on {row.name}
web/src/automation/automationApi.ts CHANGED
@@ -458,6 +458,16 @@ export interface DiscoverFieldMeta {
458
  populated: boolean;
459
  /** A condition on this field actually cuts the corpus down. */
460
  narrowing: boolean;
 
 
 
 
 
 
 
 
 
 
461
  }
462
 
463
  /**
 
458
  populated: boolean;
459
  /** A condition on this field actually cuts the corpus down. */
460
  narrowing: boolean;
461
+ /**
462
+ * The comparison a NEW condition on this field starts with β€” SERVER-OWNED, and optional only
463
+ * because an older server does not send it.
464
+ *
465
+ * β›” Do not replace an absent one with a client default. That is the whole defect this field
466
+ * exists to fix: the client used to pick `is_not_null` for every field, which the server's
467
+ * narrowing guard refuses on every field, so a filter stayed unsaveable no matter what the
468
+ * user toggled on.
469
+ */
470
+ defaultOperator?: string;
471
  }
472
 
473
  /**