fsanyoto commited on
Commit
3289587
·
verified ·
1 Parent(s): 5b27402

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
- "current": "1d4cb4d69",
3
  "releases": []
4
  }
 
1
  {
2
+ "current": "e9d79f3a7",
3
  "releases": []
4
  }
VERSION CHANGED
@@ -1 +1 @@
1
- 1d4cb4d69
 
1
+ e9d79f3a7
api/routes_query.py CHANGED
@@ -1049,15 +1049,16 @@ def _call_model(question, snapshot, model=MODEL_AUTO, chat=None, history=None, s
1049
  prompt += "\n\n" + turn["context"]
1050
  if turn.get("conversation"):
1051
  names = turn.get("conversationSources")
 
1052
  prompt += CONVERSATION_PROMPT + ("" if names is None else
1053
- " The databases this user can open: " + "; ".join(names) + "."
1054
- if names else " This user can open no database yet.")
1055
  if turn.get("toolShareRequests"):
1056
  prompt += ("\nThis turn concerns a pending tool-share approval only. Use the prior conversation to identify "
1057
  "the request. Ask which request when the user's approval is ambiguous. "
1058
  "No other write is authorized. The user already said yes to these requests: "
1059
  + json.dumps(turn["toolShareApproved"]) + ".")
1060
- if turn.get("channel") and not turn.get("memoryOnly"):
1061
  prompt += "\nThis is a shared channel. Only build_view over this snapshot is available."
1062
  if session is not None:
1063
  if not turn.get("channel"):
@@ -1264,6 +1265,7 @@ def _request_model(messages, tools, requested, session, chosen=None, *, before_a
1264
  # What changes is that each entry is now a sentence rather than a status code.
1265
  trouble = []
1266
  tried = set()
 
1267
 
1268
  def pause():
1269
  if not turn.get("providerPaused"):
@@ -1399,6 +1401,10 @@ def _request_model(messages, tools, requested, session, chosen=None, *, before_a
1399
  # the next provider is right, and swallowing it as an empty answer would show the
1400
  # reader a blank reply [[empty-answer-vs-unfinished-answer]].
1401
  trouble.append("provider answered with nothing")
 
 
 
 
1402
  except provider_stream.StreamFailure as exc:
1403
  _book(provider, exc.body)
1404
  return None, _RefusalDetail("provider stream interrupted"), provider["name"], "provider_stream_error"
@@ -2030,11 +2036,13 @@ def _submit_active(body, session, question, selected_model, context_hint, dock,
2030
  open_work = (dock is None and not target and replay is None and not also_as and door != "slack"
2031
  and assistant_open_items.admits(question))
2032
  memory_only = dock is None and not target and replay is None and assistant_memory.admits(question)
2033
- routed = _route(session, question) if dock is None and not open_work and not admitted and not memory_only and not share_requests and not agent_runtime.has_attachments() and not target and replay is None else {
 
 
 
2034
  "database": target, "auto": False, "alternatives": []}
2035
- # D-2673: an app turn with no data subject reaches the model with no tools, never the no-source refusal.
2036
- conversation = (door == "app" and dock is None and replay is None and not also_as
2037
- and _conversation(question, routed))
2038
  if conversation:
2039
  routed = {"database": "", "label": "", "reason": "", "auto": True, "alternatives": []}
2040
  target = routed["database"]
@@ -2090,7 +2098,7 @@ def _submit_active(body, session, question, selected_model, context_hint, dock,
2090
  turn["memoryOnly"] = True
2091
  if conversation:
2092
  turn["conversation"] = True
2093
- turn["conversationSources"] = _readable_labels(session)
2094
  turn["memoryCompanyRequested"] = assistant_memory.company_requested(question)
2095
  if snapshot is not None:
2096
  turn["memorySources"] = [{"database": snapshot["database"],
@@ -2899,9 +2907,10 @@ def _route_candidates(session):
2899
  return candidates
2900
 
2901
 
2902
- def _readable_labels(session):
2903
  """The names of the databases this session may open: the picker's set, no record read.
2904
 
 
2905
  None when the status wall cannot be read, so a greeting still gets its reply."""
2906
  from harness import semantic as sem
2907
  try:
@@ -2909,20 +2918,36 @@ def _readable_labels(session):
2909
  definitions = (projection("user_tables", drop=("rows",)) or {}) if projection else {}
2910
  topics = {row.get("grid"): row.get("label") for row in sem.topics().values()}
2911
  statuses = assistant_source_status(session, None)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2912
  except Exception: # noqa: BLE001
2913
  return None
2914
- return sorted({_said(status.get("label") or (definitions.get(database) or {}).get("label")
2915
  or topics.get(database) or database.removeprefix("ut_").replace("_", " ")) or database
2916
- for database, status in statuses.items()
2917
- if status.get("permitted")})
 
 
 
 
 
2918
 
2919
 
2920
  def _conversation(question, routed):
2921
  """True when an auto route found no database or the question holds no data word."""
2922
- from harness import semantic as sem
2923
- return bool(routed.get("auto")) and (
2924
- not routed.get("database")
2925
- or not set(sem._route_tokens(question)) - set(sem._route_tokens(_CHAT_WORDS)))
2926
 
2927
 
2928
  def _route(session, question):
@@ -3489,7 +3514,9 @@ def governed_query(body: dict = Body(default=None),
3489
  # Preflight executes nothing. Chat derives admission again from its own question.
3490
  return {"status": "continue_chat", "routedTo": {
3491
  "database": "", "label": "", "reason": "", "auto": False, "alternatives": []}}
3492
- routed = _route(session, question) if not database else {
 
 
3493
  "database": database, "label": "", "reason": "", "auto": False, "alternatives": []}
3494
  if _conversation(question, routed):
3495
  # D-2673: a greeting or a question no database covers continues to chat, never a Clarify card.
 
1049
  prompt += "\n\n" + turn["context"]
1050
  if turn.get("conversation"):
1051
  names = turn.get("conversationSources")
1052
+ who = "everyone in this channel" if turn.get("also_as") else "this user"
1053
  prompt += CONVERSATION_PROMPT + ("" if names is None else
1054
+ f" The databases {who} can open: " + "; ".join(names) + "."
1055
+ if names else f" {who.capitalize()} can open no database yet.")
1056
  if turn.get("toolShareRequests"):
1057
  prompt += ("\nThis turn concerns a pending tool-share approval only. Use the prior conversation to identify "
1058
  "the request. Ask which request when the user's approval is ambiguous. "
1059
  "No other write is authorized. The user already said yes to these requests: "
1060
  + json.dumps(turn["toolShareApproved"]) + ".")
1061
+ if turn.get("channel") and not turn.get("memoryOnly") and not turn.get("conversation"):
1062
  prompt += "\nThis is a shared channel. Only build_view over this snapshot is available."
1063
  if session is not None:
1064
  if not turn.get("channel"):
 
1265
  # What changes is that each entry is now a sentence rather than a status code.
1266
  trouble = []
1267
  tried = set()
1268
+ emptied = set()
1269
 
1270
  def pause():
1271
  if not turn.get("providerPaused"):
 
1401
  # the next provider is right, and swallowing it as an empty answer would show the
1402
  # reader a blank reply [[empty-answer-vs-unfinished-answer]].
1403
  trouble.append("provider answered with nothing")
1404
+ if provider["name"] not in emptied:
1405
+ # D-9739: an empty answer streamed no text, so the same provider is asked once more.
1406
+ emptied.add(provider["name"])
1407
+ providers.insert(0, provider)
1408
  except provider_stream.StreamFailure as exc:
1409
  _book(provider, exc.body)
1410
  return None, _RefusalDetail("provider stream interrupted"), provider["name"], "provider_stream_error"
 
2036
  open_work = (dock is None and not target and replay is None and not also_as and door != "slack"
2037
  and assistant_open_items.admits(question))
2038
  memory_only = dock is None and not target and replay is None and assistant_memory.admits(question)
2039
+ # D-9738: the member doors chat like the app door. D-9740: a chat-words-only turn skips the route.
2040
+ chatting = door in ("app", "slack", "whatsapp") and dock is None and replay is None
2041
+ routed = ({"database": "", "label": "", "reason": "", "auto": True, "alternatives": []}
2042
+ if chatting and _chat_only(question) else _route(session, question)) if dock is None and not open_work and not admitted and not memory_only and not share_requests and not agent_runtime.has_attachments() and not target and replay is None else {
2043
  "database": target, "auto": False, "alternatives": []}
2044
+ # D-2673: a member turn with no data subject reaches the model with no tools, never the no-source refusal.
2045
+ conversation = chatting and _conversation(question, routed)
 
2046
  if conversation:
2047
  routed = {"database": "", "label": "", "reason": "", "auto": True, "alternatives": []}
2048
  target = routed["database"]
 
2098
  turn["memoryOnly"] = True
2099
  if conversation:
2100
  turn["conversation"] = True
2101
+ turn["conversationSources"] = _readable_labels(session, also_as)
2102
  turn["memoryCompanyRequested"] = assistant_memory.company_requested(question)
2103
  if snapshot is not None:
2104
  turn["memorySources"] = [{"database": snapshot["database"],
 
2907
  return candidates
2908
 
2909
 
2910
+ def _readable_labels(session, also_as=()):
2911
  """The names of the databases this session may open: the picker's set, no record read.
2912
 
2913
+ With `also_as` (a shared channel) only those every member may also read, the C15 wall.
2914
  None when the status wall cannot be read, so a greeting still gets its reply."""
2915
  from harness import semantic as sem
2916
  try:
 
2918
  definitions = (projection("user_tables", drop=("rows",)) or {}) if projection else {}
2919
  topics = {row.get("grid"): row.get("label") for row in sem.topics().values()}
2920
  statuses = assistant_source_status(session, None)
2921
+ permitted = [database for database, status in statuses.items() if status.get("permitted")]
2922
+ if also_as:
2923
+ import core.perm_scope as perm_scope
2924
+ from core import user_tables
2925
+ # The readable half of perm_scope.min_access, without its per-member field reads.
2926
+ members = perm_scope._read_users(tuple(also_as))
2927
+ if any(member is None or str(member.get("tenant") or "royal-imports").strip().lower()
2928
+ != str(session.tenant).strip().lower() for member in members):
2929
+ return []
2930
+ lent = user_tables.lend_defs(session.runtime)
2931
+ permitted = [database for database in permitted if all(
2932
+ perm_scope.may_read(member, database,
2933
+ st=lent if database.startswith(user_tables.KEY_PREFIX) else session.runtime)
2934
+ for member in members)]
2935
  except Exception: # noqa: BLE001
2936
  return None
2937
+ return sorted({_said(statuses[database].get("label") or (definitions.get(database) or {}).get("label")
2938
  or topics.get(database) or database.removeprefix("ut_").replace("_", " ")) or database
2939
+ for database in permitted})
2940
+
2941
+
2942
+ def _chat_only(question):
2943
+ """True when every word of the question is a conversational word."""
2944
+ from harness import semantic as sem
2945
+ return not set(sem._route_tokens(question)) - set(sem._route_tokens(_CHAT_WORDS))
2946
 
2947
 
2948
  def _conversation(question, routed):
2949
  """True when an auto route found no database or the question holds no data word."""
2950
+ return bool(routed.get("auto")) and (not routed.get("database") or _chat_only(question))
 
 
 
2951
 
2952
 
2953
  def _route(session, question):
 
3514
  # Preflight executes nothing. Chat derives admission again from its own question.
3515
  return {"status": "continue_chat", "routedTo": {
3516
  "database": "", "label": "", "reason": "", "auto": False, "alternatives": []}}
3517
+ # D-9740: a chat-words-only question needs no route, so it skips the per-database reads.
3518
+ routed = ({"database": "", "label": "", "reason": "", "auto": True, "alternatives": []}
3519
+ if _chat_only(question) else _route(session, question)) if not database else {
3520
  "database": database, "label": "", "reason": "", "auto": False, "alternatives": []}
3521
  if _conversation(question, routed):
3522
  # D-2673: a greeting or a question no database covers continues to chat, never a Clarify card.
api/slack_door.py CHANGED
@@ -127,6 +127,24 @@ class SlackClient:
127
  timeout=10, allow_redirects=False)
128
 
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  def post_reply(rt, slug, team_id, channel, username, text, *, slack, blocks=None):
131
  """Every member reply traverses the shared, tenant-bound delivery seam."""
132
  from routes_slack import deliver_channel_reply
@@ -137,7 +155,7 @@ def post_reply(rt, slug, team_id, channel, username, text, *, slack, blocks=None
137
  return result
138
  data = result if isinstance(result, dict) else {"ok": True}
139
  return SimpleNamespace(ok=data.get("ok") is True, json=lambda: data)
140
- return deliver_channel_reply(rt, channel, _text(text),
141
  principal={"tenant": slug, "username": username, "also_as": []},
142
  team_id=team_id, blocks=blocks, post=post)
143
 
 
127
  timeout=10, allow_redirects=False)
128
 
129
 
130
+ _MD_CODE = re.compile(r"(```.*?```|`[^`\n]*`)", re.S)
131
+ _MD_LINK = re.compile(r"\[([^\]\n]+)\]\((https?://[^\s()]+)\)")
132
+ _MD_HEADING = re.compile(r"^#{1,6}[ \t]+([^\n]*?)[ \t]*$", re.M)
133
+ _MD_BOLD = re.compile(r"\*\*(?=\S)([^\n]+?)\*\*")
134
+ _MD_STARS = re.compile(r"\*{2,}")
135
+
136
+
137
+ def _mrkdwn(text):
138
+ """Rewrite Markdown bold, links and headings as Slack mrkdwn, outside code spans and fences."""
139
+ parts = _MD_CODE.split(text)
140
+ for i in range(0, len(parts), 2):
141
+ part = _MD_LINK.sub(r"<\2|\1>", parts[i])
142
+ part = _MD_BOLD.sub(r"*\1*", part)
143
+ part = _MD_HEADING.sub(lambda m: "*" + m.group(1).replace("*", "") + "*" if m.group(1) else "", part)
144
+ parts[i] = _MD_STARS.sub("*", part)
145
+ return "".join(parts)
146
+
147
+
148
  def post_reply(rt, slug, team_id, channel, username, text, *, slack, blocks=None):
149
  """Every member reply traverses the shared, tenant-bound delivery seam."""
150
  from routes_slack import deliver_channel_reply
 
155
  return result
156
  data = result if isinstance(result, dict) else {"ok": True}
157
  return SimpleNamespace(ok=data.get("ok") is True, json=lambda: data)
158
+ return deliver_channel_reply(rt, channel, _mrkdwn(_text(text)),
159
  principal={"tenant": slug, "username": username, "also_as": []},
160
  team_id=team_id, blocks=blocks, post=post)
161
 
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 2d96a99b0c54d87dc083b47e8e4ff618efe36834f406dd1763eb68aef932f525
 
1
+ 390e2445a48971e9d7723fee07c9c0e38d5a6394c079b38150ca199d9200a60e