Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/routes_grid.py +3 -0
- platform/core/grid_events.py +14 -3
- web/public/AIOS_DEPLOY_RECEIPT +1 -1
- web/src/customer-grid/editOutbox.ts +37 -0
RELEASES.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": []
|
| 4 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "60c8370aae",
|
| 3 |
"releases": []
|
| 4 |
}
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
60c8370aae
|
api/routes_grid.py
CHANGED
|
@@ -2195,8 +2195,11 @@ def grid_events_route(body: dict = Body(default=None),
|
|
| 2195 |
# measure CONDITION out of a saved view. The embed always passed these; the API adapter
|
| 2196 |
# simply had not been given them — the standalone shell could read measures it could
|
| 2197 |
# never write.
|
|
|
|
|
|
|
| 2198 |
ctx = _ctx(session, g["fields"], g["pids"], scope_key=scope, via=via,
|
| 2199 |
durable_receipts=True,
|
|
|
|
| 2200 |
permission_fields=(g.get('_permission_scope') or {}).get('fields'),
|
| 2201 |
measure_keys=frozenset(m["key"] for m in g["measures"]),
|
| 2202 |
resolved_ids=frozenset(g["measure_sets"]),
|
|
|
|
| 2195 |
# measure CONDITION out of a saved view. The embed always passed these; the API adapter
|
| 2196 |
# simply had not been given them — the standalone shell could read measures it could
|
| 2197 |
# never write.
|
| 2198 |
+
# The product and customer assemblies read `ws` with these pids and no consume: lend it once.
|
| 2199 |
+
lend = None if scope.startswith("ut_") else g.get("ws")
|
| 2200 |
ctx = _ctx(session, g["fields"], g["pids"], scope_key=scope, via=via,
|
| 2201 |
durable_receipts=True,
|
| 2202 |
+
workspace_lend=lend if isinstance(lend, dict) else None,
|
| 2203 |
permission_fields=(g.get('_permission_scope') or {}).get('fields'),
|
| 2204 |
measure_keys=frozenset(m["key"] for m in g["measures"]),
|
| 2205 |
resolved_ids=frozenset(g["measure_sets"]),
|
platform/core/grid_events.py
CHANGED
|
@@ -205,6 +205,8 @@ class EventCtx:
|
|
| 205 |
by: Optional[str] = None
|
| 206 |
via: Optional[str] = None
|
| 207 |
durable_receipts: bool = False
|
|
|
|
|
|
|
| 208 |
|
| 209 |
def __post_init__(self):
|
| 210 |
# A caller that forgets `seen_ids` gets per-call dedup rather than a crash — the SET is
|
|
@@ -1430,6 +1432,8 @@ def _edit_receipt(fn):
|
|
| 1430 |
ctx.out.write_id = ''
|
| 1431 |
return _refuse(ctx, 'bad_op_id', str(exc), event=event.get('type'))
|
| 1432 |
event = dict(event, id=identity)
|
|
|
|
|
|
|
| 1433 |
|
| 1434 |
def apply():
|
| 1435 |
before = len(ctx.out.refusals)
|
|
@@ -1437,7 +1441,7 @@ def _edit_receipt(fn):
|
|
| 1437 |
table = copy(ctx.table) if ctx.table is not None else None
|
| 1438 |
if table is not None:
|
| 1439 |
table._st = checked
|
| 1440 |
-
write_ctx = replace(ctx, st=checked, table=table)
|
| 1441 |
rerender = fn(event, write_ctx)
|
| 1442 |
write = dict(ctx.out.writes.get(identity) or {})
|
| 1443 |
write['opId'] = identity
|
|
@@ -1516,6 +1520,8 @@ def handle_one(event, ctx):
|
|
| 1516 |
visible_views = ctx.visible_views
|
| 1517 |
admin = ctx.admin
|
| 1518 |
scope_key = ctx.scope_key
|
|
|
|
|
|
|
| 1519 |
|
| 1520 |
if not isinstance(event, dict):
|
| 1521 |
return False
|
|
@@ -1570,8 +1576,13 @@ def handle_one(event, ctx):
|
|
| 1570 |
if f.get('source') == 'overlay' or _may_override_source_value(f)}
|
| 1571 |
# Event validation is not a render payload. It must not consume a one-shot label
|
| 1572 |
# correction before the browser has had a chance to receive it.
|
| 1573 |
-
ws
|
| 1574 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1575 |
|
| 1576 |
def _session_ready():
|
| 1577 |
ws.setdefault('views', {})
|
|
|
|
| 205 |
by: Optional[str] = None
|
| 206 |
via: Optional[str] = None
|
| 207 |
durable_receipts: bool = False
|
| 208 |
+
#: The route's assembly workspace, lent to the first event only (`handle_one`).
|
| 209 |
+
workspace_lend: Optional[dict] = None
|
| 210 |
|
| 211 |
def __post_init__(self):
|
| 212 |
# A caller that forgets `seen_ids` gets per-call dedup rather than a crash — the SET is
|
|
|
|
| 1432 |
ctx.out.write_id = ''
|
| 1433 |
return _refuse(ctx, 'bad_op_id', str(exc), event=event.get('type'))
|
| 1434 |
event = dict(event, id=identity)
|
| 1435 |
+
# The write runs on a copy, so the lend leaves the outer ctx here, replays included.
|
| 1436 |
+
lend, ctx.workspace_lend = ctx.workspace_lend, None
|
| 1437 |
|
| 1438 |
def apply():
|
| 1439 |
before = len(ctx.out.refusals)
|
|
|
|
| 1441 |
table = copy(ctx.table) if ctx.table is not None else None
|
| 1442 |
if table is not None:
|
| 1443 |
table._st = checked
|
| 1444 |
+
write_ctx = replace(ctx, st=checked, table=table, workspace_lend=lend)
|
| 1445 |
rerender = fn(event, write_ctx)
|
| 1446 |
write = dict(ctx.out.writes.get(identity) or {})
|
| 1447 |
write['opId'] = identity
|
|
|
|
| 1520 |
visible_views = ctx.visible_views
|
| 1521 |
admin = ctx.admin
|
| 1522 |
scope_key = ctx.scope_key
|
| 1523 |
+
# A lent workspace is a pre-write snapshot: one event takes it, never a later one.
|
| 1524 |
+
lend, ctx.workspace_lend = ctx.workspace_lend, None
|
| 1525 |
|
| 1526 |
if not isinstance(event, dict):
|
| 1527 |
return False
|
|
|
|
| 1576 |
if f.get('source') == 'overlay' or _may_override_source_value(f)}
|
| 1577 |
# Event validation is not a render payload. It must not consume a one-shot label
|
| 1578 |
# correction before the browser has had a chance to receive it.
|
| 1579 |
+
# Only the view kinds take the lend: they read `ws['views']`, which the assembly never merges.
|
| 1580 |
+
if (kind in ('view_upsert', 'view_delete') and isinstance(lend, dict)
|
| 1581 |
+
and _store_of(ctx).available()):
|
| 1582 |
+
ws = lend
|
| 1583 |
+
else:
|
| 1584 |
+
ws = table_workspace(
|
| 1585 |
+
ctx, allowed_pids=allowed_pids, consume_corrections=False)
|
| 1586 |
|
| 1587 |
def _session_ready():
|
| 1588 |
ws.setdefault('views', {})
|
web/public/AIOS_DEPLOY_RECEIPT
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
373129ffaf60d776638c3e7ff45e44bd1e880a352341fb1fe46d68f1ea853cde
|
web/src/customer-grid/editOutbox.ts
CHANGED
|
@@ -309,6 +309,7 @@ export function createEditOutbox(options: {
|
|
| 309 |
if (!await start()) return false;
|
| 310 |
for (const entry of [...entries]) {
|
| 311 |
if (generation !== epoch) return false;
|
|
|
|
| 312 |
try { await persist(entry); }
|
| 313 |
catch (error) {
|
| 314 |
if (generation !== epoch) return false;
|
|
@@ -325,6 +326,40 @@ export function createEditOutbox(options: {
|
|
| 325 |
serial = task.then(() => undefined);
|
| 326 |
return task;
|
| 327 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
const nextEntry = (): PendingEdit | undefined => {
|
| 329 |
const held: OutboxEdit[] = [];
|
| 330 |
for (const candidate of entries) {
|
|
@@ -357,6 +392,7 @@ export function createEditOutbox(options: {
|
|
| 357 |
try {
|
| 358 |
if (!entry.stored && !await persistAll()) return;
|
| 359 |
if (generation !== epoch) return;
|
|
|
|
| 360 |
attempting = entry;
|
| 361 |
publish();
|
| 362 |
const current = await attempt(options.identity, identityTimeout);
|
|
@@ -460,6 +496,7 @@ export function createEditOutbox(options: {
|
|
| 460 |
if (entries.some((entry) => entry.edit.id === edit.id)) return Promise.resolve(false);
|
| 461 |
const entry: PendingEdit = { edit: structuredClone(edit), attempted };
|
| 462 |
const answer = new Promise<boolean>((resolve) => { entry.settle = resolve; });
|
|
|
|
| 463 |
entries.push(entry);
|
| 464 |
publish();
|
| 465 |
// Serial persistence preserves field-before-view order, including the IndexedDB gap.
|
|
|
|
| 309 |
if (!await start()) return false;
|
| 310 |
for (const entry of [...entries]) {
|
| 311 |
if (generation !== epoch) return false;
|
| 312 |
+
if (!entries.includes(entry)) continue;
|
| 313 |
try { await persist(entry); }
|
| 314 |
catch (error) {
|
| 315 |
if (generation !== epoch) return false;
|
|
|
|
| 326 |
serial = task.then(() => undefined);
|
| 327 |
return task;
|
| 328 |
};
|
| 329 |
+
const viewSave = (edit: OutboxEdit): string | undefined => {
|
| 330 |
+
const payload = edit.payload as { type?: unknown; view?: { id?: unknown } | null } | null;
|
| 331 |
+
return edit.kind === "event" && payload?.type === "view_upsert" && typeof payload.view?.id === "string"
|
| 332 |
+
&& !("action" in payload) ? payload.view.id : undefined;
|
| 333 |
+
};
|
| 334 |
+
const mentionsView = (edit: OutboxEdit, id: string): boolean => {
|
| 335 |
+
const payload = edit.payload as { viewId?: unknown; itemId?: unknown; view?: { id?: unknown } | null } | null;
|
| 336 |
+
return payload?.viewId === id || payload?.itemId === id || payload?.view?.id === id;
|
| 337 |
+
};
|
| 338 |
+
// A newer whole-view save drops older queued saves of that view, back to its first in-flight, failed or other view event.
|
| 339 |
+
const supersede = (edit: OutboxEdit): void => {
|
| 340 |
+
const id = viewSave(edit);
|
| 341 |
+
if (id === undefined) return;
|
| 342 |
+
const workspace = (scope: string) => scope === "cohort" ? "customer" : scope;
|
| 343 |
+
const dropped: PendingEdit[] = [];
|
| 344 |
+
for (let index = entries.length - 1; index >= 0; index--) {
|
| 345 |
+
const queued = entries[index];
|
| 346 |
+
if (workspace(queued.edit.scope) !== workspace(edit.scope) || !mentionsView(queued.edit, id)) continue;
|
| 347 |
+
if (queued === attempting || queued.failure || queued.edit.scope !== edit.scope
|
| 348 |
+
|| viewSave(queued.edit) !== id) break;
|
| 349 |
+
entries.splice(index, 1);
|
| 350 |
+
dropped.push(queued);
|
| 351 |
+
}
|
| 352 |
+
if (!dropped.length) return;
|
| 353 |
+
for (const queued of dropped) {
|
| 354 |
+
queued.settle?.(false);
|
| 355 |
+
queued.settle = undefined;
|
| 356 |
+
}
|
| 357 |
+
// Runs after any persist already queued, so a copy written meanwhile is removed too.
|
| 358 |
+
const removal = serial.then(async () => {
|
| 359 |
+
for (const queued of dropped) if (queued.stored) await store.remove(queued.stored);
|
| 360 |
+
});
|
| 361 |
+
serial = removal.catch(() => undefined);
|
| 362 |
+
};
|
| 363 |
const nextEntry = (): PendingEdit | undefined => {
|
| 364 |
const held: OutboxEdit[] = [];
|
| 365 |
for (const candidate of entries) {
|
|
|
|
| 392 |
try {
|
| 393 |
if (!entry.stored && !await persistAll()) return;
|
| 394 |
if (generation !== epoch) return;
|
| 395 |
+
if (!entries.includes(entry)) continue;
|
| 396 |
attempting = entry;
|
| 397 |
publish();
|
| 398 |
const current = await attempt(options.identity, identityTimeout);
|
|
|
|
| 496 |
if (entries.some((entry) => entry.edit.id === edit.id)) return Promise.resolve(false);
|
| 497 |
const entry: PendingEdit = { edit: structuredClone(edit), attempted };
|
| 498 |
const answer = new Promise<boolean>((resolve) => { entry.settle = resolve; });
|
| 499 |
+
supersede(entry.edit);
|
| 500 |
entries.push(entry);
|
| 501 |
publish();
|
| 502 |
// Serial persistence preserves field-before-view order, including the IndexedDB gap.
|