Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/routes_query.py +44 -17
- api/slack_door.py +19 -1
- web/public/AIOS_DEPLOY_RECEIPT +1 -1
RELEASES.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v81",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "cd742396c432 (cd742396c432)",
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v81",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
cd742396c432 (cd742396c432)
|
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
|
| 1054 |
-
if names else "
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 2034 |
"database": target, "auto": False, "alternatives": []}
|
| 2035 |
-
# D-2673:
|
| 2036 |
-
conversation =
|
| 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"],
|
|
@@ -2771,9 +2779,10 @@ def _route_candidates(session):
|
|
| 2771 |
return candidates
|
| 2772 |
|
| 2773 |
|
| 2774 |
-
def _readable_labels(session):
|
| 2775 |
"""The names of the databases this session may open: the picker's set, no record read.
|
| 2776 |
|
|
|
|
| 2777 |
None when the status wall cannot be read, so a greeting still gets its reply."""
|
| 2778 |
from harness import semantic as sem
|
| 2779 |
try:
|
|
@@ -2781,20 +2790,36 @@ def _readable_labels(session):
|
|
| 2781 |
definitions = (projection("user_tables", drop=("rows",)) or {}) if projection else {}
|
| 2782 |
topics = {row.get("grid"): row.get("label") for row in sem.topics().values()}
|
| 2783 |
statuses = assistant_source_status(session, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2784 |
except Exception: # noqa: BLE001
|
| 2785 |
return None
|
| 2786 |
-
return sorted({_said(
|
| 2787 |
or topics.get(database) or database.removeprefix("ut_").replace("_", " ")) or database
|
| 2788 |
-
for database
|
| 2789 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2790 |
|
| 2791 |
|
| 2792 |
def _conversation(question, routed):
|
| 2793 |
"""True when an auto route found no database or the question holds no data word."""
|
| 2794 |
-
|
| 2795 |
-
return bool(routed.get("auto")) and (
|
| 2796 |
-
not routed.get("database")
|
| 2797 |
-
or not set(sem._route_tokens(question)) - set(sem._route_tokens(_CHAT_WORDS)))
|
| 2798 |
|
| 2799 |
|
| 2800 |
def _route(session, question):
|
|
@@ -3361,7 +3386,9 @@ def governed_query(body: dict = Body(default=None),
|
|
| 3361 |
# Preflight executes nothing. Chat derives admission again from its own question.
|
| 3362 |
return {"status": "continue_chat", "routedTo": {
|
| 3363 |
"database": "", "label": "", "reason": "", "auto": False, "alternatives": []}}
|
| 3364 |
-
|
|
|
|
|
|
|
| 3365 |
"database": database, "label": "", "reason": "", "auto": False, "alternatives": []}
|
| 3366 |
if _conversation(question, routed):
|
| 3367 |
# 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"],
|
|
|
|
| 2779 |
return candidates
|
| 2780 |
|
| 2781 |
|
| 2782 |
+
def _readable_labels(session, also_as=()):
|
| 2783 |
"""The names of the databases this session may open: the picker's set, no record read.
|
| 2784 |
|
| 2785 |
+
With `also_as` (a shared channel) only those every member may also read, the C15 wall.
|
| 2786 |
None when the status wall cannot be read, so a greeting still gets its reply."""
|
| 2787 |
from harness import semantic as sem
|
| 2788 |
try:
|
|
|
|
| 2790 |
definitions = (projection("user_tables", drop=("rows",)) or {}) if projection else {}
|
| 2791 |
topics = {row.get("grid"): row.get("label") for row in sem.topics().values()}
|
| 2792 |
statuses = assistant_source_status(session, None)
|
| 2793 |
+
permitted = [database for database, status in statuses.items() if status.get("permitted")]
|
| 2794 |
+
if also_as:
|
| 2795 |
+
import core.perm_scope as perm_scope
|
| 2796 |
+
from core import user_tables
|
| 2797 |
+
# The readable half of perm_scope.min_access, without its per-member field reads.
|
| 2798 |
+
members = perm_scope._read_users(tuple(also_as))
|
| 2799 |
+
if any(member is None or str(member.get("tenant") or "royal-imports").strip().lower()
|
| 2800 |
+
!= str(session.tenant).strip().lower() for member in members):
|
| 2801 |
+
return []
|
| 2802 |
+
lent = user_tables.lend_defs(session.runtime)
|
| 2803 |
+
permitted = [database for database in permitted if all(
|
| 2804 |
+
perm_scope.may_read(member, database,
|
| 2805 |
+
st=lent if database.startswith(user_tables.KEY_PREFIX) else session.runtime)
|
| 2806 |
+
for member in members)]
|
| 2807 |
except Exception: # noqa: BLE001
|
| 2808 |
return None
|
| 2809 |
+
return sorted({_said(statuses[database].get("label") or (definitions.get(database) or {}).get("label")
|
| 2810 |
or topics.get(database) or database.removeprefix("ut_").replace("_", " ")) or database
|
| 2811 |
+
for database in permitted})
|
| 2812 |
+
|
| 2813 |
+
|
| 2814 |
+
def _chat_only(question):
|
| 2815 |
+
"""True when every word of the question is a conversational word."""
|
| 2816 |
+
from harness import semantic as sem
|
| 2817 |
+
return not set(sem._route_tokens(question)) - set(sem._route_tokens(_CHAT_WORDS))
|
| 2818 |
|
| 2819 |
|
| 2820 |
def _conversation(question, routed):
|
| 2821 |
"""True when an auto route found no database or the question holds no data word."""
|
| 2822 |
+
return bool(routed.get("auto")) and (not routed.get("database") or _chat_only(question))
|
|
|
|
|
|
|
|
|
|
| 2823 |
|
| 2824 |
|
| 2825 |
def _route(session, question):
|
|
|
|
| 3386 |
# Preflight executes nothing. Chat derives admission again from its own question.
|
| 3387 |
return {"status": "continue_chat", "routedTo": {
|
| 3388 |
"database": "", "label": "", "reason": "", "auto": False, "alternatives": []}}
|
| 3389 |
+
# D-9740: a chat-words-only question needs no route, so it skips the per-database reads.
|
| 3390 |
+
routed = ({"database": "", "label": "", "reason": "", "auto": True, "alternatives": []}
|
| 3391 |
+
if _chat_only(question) else _route(session, question)) if not database else {
|
| 3392 |
"database": database, "label": "", "reason": "", "auto": False, "alternatives": []}
|
| 3393 |
if _conversation(question, routed):
|
| 3394 |
# 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 |
-
|
|
|
|
| 1 |
+
08c7bda728edb6bb756915447bda355188f95839b1c8f8519dd3ee44b3ae4299
|