Spaces:
Running

fsanyoto commited on
Commit
3cfdf9c
·
verified ·
1 Parent(s): 0834dd0

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
- "current": "12a9276481",
3
  "releases": []
4
  }
 
1
  {
2
+ "current": "0aa73ff8c1",
3
  "releases": []
4
  }
VERSION CHANGED
@@ -1 +1 @@
1
- 12a9276481
 
1
+ 0aa73ff8c1
api/application_registry.py CHANGED
@@ -5,6 +5,8 @@ import base64
5
  import copy
6
  import hashlib
7
  import json
 
 
8
  from core import shares, write_execution
9
  from core.request_timing import raise_if_resource_error
10
  import app_rules
@@ -535,14 +537,38 @@ def _request_memo():
535
  return acc, acc.__dict__.setdefault("application_registry_memo", {}), acc.read_memo_epoch
536
 
537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
538
  def load(runtime, *, strict=False):
539
  """The read door: a Routing or Catalog App carries its C1 binding (`app_templates.bound`)."""
540
  memo, key = _request_memo(), (getattr(runtime, "key", None), id(runtime))
 
 
 
 
541
  if memo is not None:
542
  acc, table, epoch = memo
543
  with acc.lock:
544
  hit = table.get(key)
545
  if hit and hit[0] == epoch == acc.read_memo_epoch:
 
 
546
  return copy.deepcopy(hit[1])
547
  try:
548
  doc = _clean_doc(runtime.get(_KEY))
@@ -558,6 +584,8 @@ def load(runtime, *, strict=False):
558
  if memo is not None:
559
  with acc.lock:
560
  table[key] = (epoch, copy.deepcopy(doc))
 
 
561
  return doc
562
 
563
 
 
5
  import copy
6
  import hashlib
7
  import json
8
+ from contextlib import contextmanager
9
+ from contextvars import ContextVar
10
  from core import shares, write_execution
11
  from core.request_timing import raise_if_resource_error
12
  import app_rules
 
537
  return acc, acc.__dict__.setdefault("application_registry_memo", {}), acc.read_memo_epoch
538
 
539
 
540
+ _PINNED = ContextVar("application_registry_pinned", default=None)
541
+
542
+
543
+ @contextmanager
544
+ def pinned():
545
+ """Serve every `load` in a block that writes no App from one registry read; nesting shares it.
546
+
547
+ The request memo ends 2 s into a request, so without a pin a long describer reloads per check."""
548
+ if _PINNED.get() is not None:
549
+ yield
550
+ return
551
+ token = _PINNED.set({})
552
+ try:
553
+ yield
554
+ finally:
555
+ _PINNED.reset(token)
556
+
557
+
558
  def load(runtime, *, strict=False):
559
  """The read door: a Routing or Catalog App carries its C1 binding (`app_templates.bound`)."""
560
  memo, key = _request_memo(), (getattr(runtime, "key", None), id(runtime))
561
+ # Scope checks wrap the store in fresh runtime objects, so the pin keys on the tenant alone.
562
+ pin, tenant = _PINNED.get(), getattr(runtime, "key", None)
563
+ if pin is not None and tenant in pin:
564
+ return copy.deepcopy(pin[tenant])
565
  if memo is not None:
566
  acc, table, epoch = memo
567
  with acc.lock:
568
  hit = table.get(key)
569
  if hit and hit[0] == epoch == acc.read_memo_epoch:
570
+ if pin is not None:
571
+ pin[tenant] = copy.deepcopy(hit[1])
572
  return copy.deepcopy(hit[1])
573
  try:
574
  doc = _clean_doc(runtime.get(_KEY))
 
584
  if memo is not None:
585
  with acc.lock:
586
  table[key] = (epoch, copy.deepcopy(doc))
587
+ if pin is not None:
588
+ pin[tenant] = copy.deepcopy(doc)
589
  return doc
590
 
591
 
api/routes_external.py CHANGED
@@ -4,6 +4,7 @@ import dash_norm
4
  import base64
5
  import html as _html
6
  import copy
 
7
  import hashlib
8
  import hmac
9
  import importlib
@@ -1586,6 +1587,17 @@ def _credential_audit(kind: str, session: Session, credential_kind: str, **detai
1586
  audit.record(kind, session.tenant, session.uname, safe)
1587
 
1588
 
 
 
 
 
 
 
 
 
 
 
 
1589
  def _resolve_external_scope(
1590
  session: Session,
1591
  databases=None,
@@ -6731,6 +6743,7 @@ def _guide_connections(session: Session) -> list[dict]:
6731
 
6732
  known_clients = {key: label for key, label, _aliases in AI_CONTACT_CLIENTS}
6733
  connected = {}
 
6734
  for person in users.assignable_identities(session.tenant):
6735
  username = person["username"]
6736
  user = external_access.resolve_active_user(username, session.tenant)
@@ -6744,7 +6757,7 @@ def _guide_connections(session: Session) -> list[dict]:
6744
  names.append(external_oauth.label_for(session.runtime, grant["id"]))
6745
  except external_oauth.ExternalOAuthAuthError:
6746
  continue
6747
- for key in external_access.list_for_user(session.runtime, username, session.tenant):
6748
  client = _external_client_id(key)
6749
  if client and key.get("last_used") and _external_active(key):
6750
  names.append(known_clients[client])
@@ -7106,8 +7119,10 @@ def _mcp_guide_group_note(requested, groups) -> str:
7106
 
7107
  def _mcp_guide(session: Session, group=None) -> str:
7108
  """Return the group index or one group's action schemas without reading records."""
 
7109
  try:
7110
- return _mcp_guide_text(session, group)
 
7111
  except HTTPException as exc:
7112
  info = exc.detail.get("error", {}) if isinstance(exc.detail, dict) else {}
7113
  if exc.status_code in (401, 403, 404, 429) or exc.status_code >= 500 or info.get("code") in MCP_RESULT_CODES:
 
4
  import base64
5
  import html as _html
6
  import copy
7
+ import functools
8
  import hashlib
9
  import hmac
10
  import importlib
 
1587
  audit.record(kind, session.tenant, session.uname, safe)
1588
 
1589
 
1590
+ def _app_registry_pinned(fn):
1591
+ """Run a read-only describer over one App registry read (`application_registry.pinned`)."""
1592
+ @functools.wraps(fn)
1593
+ def pinned(*args, **kwargs):
1594
+ import application_registry
1595
+ with application_registry.pinned():
1596
+ return fn(*args, **kwargs)
1597
+ return pinned
1598
+
1599
+
1600
+ @_app_registry_pinned
1601
  def _resolve_external_scope(
1602
  session: Session,
1603
  databases=None,
 
6743
 
6744
  known_clients = {key: label for key, label, _aliases in AI_CONTACT_CLIENTS}
6745
  connected = {}
6746
+ keys_by_owner = external_access.list_by_owner(session.runtime, session.tenant)
6747
  for person in users.assignable_identities(session.tenant):
6748
  username = person["username"]
6749
  user = external_access.resolve_active_user(username, session.tenant)
 
6757
  names.append(external_oauth.label_for(session.runtime, grant["id"]))
6758
  except external_oauth.ExternalOAuthAuthError:
6759
  continue
6760
+ for key in keys_by_owner.get(str(username or "").strip().lower(), ()):
6761
  client = _external_client_id(key)
6762
  if client and key.get("last_used") and _external_active(key):
6763
  names.append(known_clients[client])
 
7119
 
7120
  def _mcp_guide(session: Session, group=None) -> str:
7121
  """Return the group index or one group's action schemas without reading records."""
7122
+ import application_registry
7123
  try:
7124
+ with application_registry.pinned():
7125
+ return _mcp_guide_text(session, group)
7126
  except HTTPException as exc:
7127
  info = exc.detail.get("error", {}) if isinstance(exc.detail, dict) else {}
7128
  if exc.status_code in (401, 403, 404, 429) or exc.status_code >= 500 or info.get("code") in MCP_RESULT_CODES:
platform/core/external_access.py CHANGED
@@ -467,6 +467,22 @@ def list_for_user(st, username: str, tenant: str) -> list[dict]:
467
  return sorted(records, key=lambda row: str(row.get("created") or ""), reverse=True)
468
 
469
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
470
  def revoke(st, username: str, tenant: str, key_id: str) -> dict:
471
  """Tombstone one credential owned by this user; foreign and absent IDs are identical."""
472
  owner, tenant_key = _normalise_owner(username, tenant)
 
467
  return sorted(records, key=lambda row: str(row.get("created") or ""), reverse=True)
468
 
469
 
470
+ def list_by_owner(st, tenant: str) -> dict[str, list[dict]]:
471
+ """Every owner's active credential metadata, newest first, from ONE read of the book."""
472
+ tenant_key = str(tenant or "").strip().lower()
473
+ if not tenant_key:
474
+ raise ExternalAccessError("external_identity_invalid")
475
+ _assert_bound_runtime(st, tenant_key)
476
+ owners: dict[str, list[dict]] = {}
477
+ for record in _book(st).values():
478
+ if (isinstance(record, dict) and record.get("tenant") == tenant_key
479
+ and not record.get("revoked_at") and isinstance(record.get("username"), str)):
480
+ owners.setdefault(record["username"], []).append(_metadata(record))
481
+ for rows in owners.values():
482
+ rows.sort(key=lambda row: str(row.get("created") or ""), reverse=True)
483
+ return owners
484
+
485
+
486
  def revoke(st, username: str, tenant: str, key_id: str) -> dict:
487
  """Tombstone one credential owned by this user; foreign and absent IDs are identical."""
488
  owner, tenant_key = _normalise_owner(username, tenant)
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- c54488570a80aec1adda057034e2a653209ce6ea45309e01725d841d9c7bf6b3
 
1
+ 8b8bf8ec71574952ec46b7fb2bc797cd7e005c9fe481b34160614eb10c7b4324