Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/app_guide.py +5 -2
- api/routes_external.py +31 -10
- api/routes_query.py +58 -1
- platform/core/external_tools.py +40 -0
- web/public/AIOS_DEPLOY_RECEIPT +1 -1
RELEASES.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": []
|
| 4 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "1d4cb4d69",
|
| 3 |
"releases": []
|
| 4 |
}
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
1d4cb4d69
|
api/app_guide.py
CHANGED
|
@@ -225,16 +225,19 @@ def _chart_guidance():
|
|
| 225 |
|
| 226 |
def _catalog_guidance():
|
| 227 |
"""Append the same template library as the client and the current build argument schema."""
|
|
|
|
| 228 |
from loopy_catalog_tools import build_schema
|
| 229 |
|
| 230 |
library = json.dumps(app_rules.catalog_templates(), ensure_ascii=True, indent=2)
|
| 231 |
-
|
|
|
|
|
|
|
| 232 |
return ("\n# Current Catalog template library\n\n"
|
| 233 |
"These IDs, slots and design defaults also come from GET /api/v1/catalogs/templates.\n"
|
| 234 |
f"```json\n{library}\n```\n"
|
| 235 |
"\n# Current catalog_build argument schema\n\n"
|
| 236 |
"This schema describes arguments only. Put about and intent beside action and arguments.\n"
|
| 237 |
-
f"```json\n{schema}\n```\n")
|
| 238 |
|
| 239 |
|
| 240 |
def read(section=None):
|
|
|
|
| 225 |
|
| 226 |
def _catalog_guidance():
|
| 227 |
"""Append the same template library as the client and the current build argument schema."""
|
| 228 |
+
from core import external_tools
|
| 229 |
from loopy_catalog_tools import build_schema
|
| 230 |
|
| 231 |
library = json.dumps(app_rules.catalog_templates(), ensure_ascii=True, indent=2)
|
| 232 |
+
collapsed, used = external_tools.guide_schema(build_schema())
|
| 233 |
+
schema = json.dumps(collapsed, ensure_ascii=True, indent=2)
|
| 234 |
+
nodes = "\n" + external_tools.filter_node_guide() + "\n" if used else ""
|
| 235 |
return ("\n# Current Catalog template library\n\n"
|
| 236 |
"These IDs, slots and design defaults also come from GET /api/v1/catalogs/templates.\n"
|
| 237 |
f"```json\n{library}\n```\n"
|
| 238 |
"\n# Current catalog_build argument schema\n\n"
|
| 239 |
"This schema describes arguments only. Put about and intent beside action and arguments.\n"
|
| 240 |
+
f"```json\n{schema}\n```\n{nodes}")
|
| 241 |
|
| 242 |
|
| 243 |
def read(section=None):
|
api/routes_external.py
CHANGED
|
@@ -5196,7 +5196,9 @@ def _mcp_guide(session: Session, group=None) -> str:
|
|
| 5196 |
"Call a group with action and arguments. Each action keeps its own read or write rules.",
|
| 5197 |
"Every tool accepts optional intent beside action and arguments. Every write requires it, including "
|
| 5198 |
"previews, confirm_change, requests.send and intelligence.create_wiki. Use 1 to 500 characters. "
|
| 5199 |
-
'Example: {"intent":"Prepare the weekly sales review"}. Intent is stripped before dispatch.'
|
|
|
|
|
|
|
| 5200 |
"Each tool call records one external.query event with tool, action, outcome and argument keys and types. "
|
| 5201 |
"Large shapes continue in argument_shape_1 and later numbered fields. Unknown keys are redacted. "
|
| 5202 |
"Argument values are never recorded. Intent is retained only when sent, with credential patterns redacted. "
|
|
@@ -5208,7 +5210,7 @@ def _mcp_guide(session: Session, group=None) -> str:
|
|
| 5208 |
"characters, and one or more distinct tags below. intelligence.create_wiki needs the same about "
|
| 5209 |
"and still publishes directly. The tool supplies the build kind. Confirmation uses the saved about.",
|
| 5210 |
"Build tags: " + ", ".join(external_tools.BUILD_TAGS) + ".",
|
| 5211 |
-
"For a previewed build, put optional purpose beside action and arguments
|
| 5212 |
"Use one line of 1 to 240 characters without control characters or long dashes. "
|
| 5213 |
"Confirmation uses that saved purpose; do not send a new purpose to confirm_change.",
|
| 5214 |
"Previous tool names remain callable for one release, but are absent from tools/list.", ""]
|
|
@@ -5223,6 +5225,7 @@ def _mcp_guide(session: Session, group=None) -> str:
|
|
| 5223 |
from tool_groups.data import query_guide
|
| 5224 |
lines += [query_guide(rows), ""]
|
| 5225 |
states = {row["action"]: row for row in capabilities if row["group"] == group}
|
|
|
|
| 5226 |
for action, entry in selected["actions"].items():
|
| 5227 |
lines += ["### " + action,
|
| 5228 |
"State: " + states[action]["state"] + "."
|
|
@@ -5234,7 +5237,11 @@ def _mcp_guide(session: Session, group=None) -> str:
|
|
| 5234 |
lines.append("Previous name: `" + entry["legacy_name"] + "`.")
|
| 5235 |
schema = copy.deepcopy(entry["schema"])
|
| 5236 |
schema.get("properties", {}).pop("about", None)
|
|
|
|
|
|
|
| 5237 |
lines += ["```json", json.dumps(_mcp_schema_copy(schema), ensure_ascii=True, indent=2), "```", ""]
|
|
|
|
|
|
|
| 5238 |
return _MCPGuideText("\n".join(lines) + "\n")
|
| 5239 |
lines += ["## Connected AI clients", "",
|
| 5240 |
"Client names and who connected them in this workspace. No entries means none are connected.",
|
|
@@ -5365,13 +5372,14 @@ def _handle_mcp(req, session: Session, base_url: str = ""):
|
|
| 5365 |
return reply
|
| 5366 |
params = req.get("params")
|
| 5367 |
params = params if isinstance(params, dict) else {}
|
| 5368 |
-
|
| 5369 |
-
|
|
|
|
| 5370 |
try:
|
| 5371 |
with external_activity.capture_call(session, tool) as call:
|
| 5372 |
if tool == limitation_tool:
|
| 5373 |
external_activity.note_action(limitation_action)
|
| 5374 |
-
external_activity.note_arguments(
|
| 5375 |
metadata = params.get("_meta")
|
| 5376 |
call["question"] = metadata.get("loopable/question") if isinstance(metadata, dict) else None
|
| 5377 |
reply = _dispatch_mcp(req, session, base_url)
|
|
@@ -5451,6 +5459,23 @@ def _mcp_call_intent(arguments):
|
|
| 5451 |
return value
|
| 5452 |
|
| 5453 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5454 |
def _mcp_requires_intent(name, arguments):
|
| 5455 |
"""Classify declared writes before argument validation can mask the intent requirement."""
|
| 5456 |
if name == "confirm_change":
|
|
@@ -5525,7 +5550,7 @@ def _dispatch_mcp(req, session: Session, base_url: str = ""):
|
|
| 5525 |
return {"jsonrpc": "2.0", "id": rid, "result": {"contents": [resource]}}
|
| 5526 |
if method != "tools/call":
|
| 5527 |
return protocol_error(rid, -32601, "The requested MCP method was not found.")
|
| 5528 |
-
arguments = params.get("arguments", {})
|
| 5529 |
intent = _mcp_call_intent(arguments)
|
| 5530 |
if intent is None and _mcp_requires_intent(name, arguments):
|
| 5531 |
raise err(400, "call_intent_required", "Send intent explaining why you are making this write.",
|
|
@@ -5548,10 +5573,6 @@ def _dispatch_mcp(req, session: Session, base_url: str = ""):
|
|
| 5548 |
purpose = _build_purpose(arguments.pop("purpose"))
|
| 5549 |
if "about" in metadata_keys:
|
| 5550 |
about = arguments.pop("about")
|
| 5551 |
-
if (name in tool_groups.groups() and isinstance(arguments, dict)
|
| 5552 |
-
and isinstance(arguments.get("arguments"), dict)
|
| 5553 |
-
and {"about", "purpose", "intent"} & arguments["arguments"].keys()):
|
| 5554 |
-
raise err(400, "tool_arguments_invalid", "Send intent and build metadata beside action and arguments.")
|
| 5555 |
_assert_tool_query_filter_bounds(name, arguments)
|
| 5556 |
resolved = tool_groups.resolve(name, arguments)
|
| 5557 |
confirm = True
|
|
|
|
| 5196 |
"Call a group with action and arguments. Each action keeps its own read or write rules.",
|
| 5197 |
"Every tool accepts optional intent beside action and arguments. Every write requires it, including "
|
| 5198 |
"previews, confirm_change, requests.send and intelligence.create_wiki. Use 1 to 500 characters. "
|
| 5199 |
+
'Example: {"intent":"Prepare the weekly sales review"}. Intent is stripped before dispatch. '
|
| 5200 |
+
"A client that cannot send keys beside action and arguments may put intent, about and purpose "
|
| 5201 |
+
"inside arguments. The value beside action and arguments wins.",
|
| 5202 |
"Each tool call records one external.query event with tool, action, outcome and argument keys and types. "
|
| 5203 |
"Large shapes continue in argument_shape_1 and later numbered fields. Unknown keys are redacted. "
|
| 5204 |
"Argument values are never recorded. Intent is retained only when sent, with credential patterns redacted. "
|
|
|
|
| 5210 |
"characters, and one or more distinct tags below. intelligence.create_wiki needs the same about "
|
| 5211 |
"and still publishes directly. The tool supplies the build kind. Confirmation uses the saved about.",
|
| 5212 |
"Build tags: " + ", ".join(external_tools.BUILD_TAGS) + ".",
|
| 5213 |
+
"For a previewed build, put optional purpose beside action and arguments. "
|
| 5214 |
"Use one line of 1 to 240 characters without control characters or long dashes. "
|
| 5215 |
"Confirmation uses that saved purpose; do not send a new purpose to confirm_change.",
|
| 5216 |
"Previous tool names remain callable for one release, but are absent from tools/list.", ""]
|
|
|
|
| 5225 |
from tool_groups.data import query_guide
|
| 5226 |
lines += [query_guide(rows), ""]
|
| 5227 |
states = {row["action"]: row for row in capabilities if row["group"] == group}
|
| 5228 |
+
uses_filter_node = False
|
| 5229 |
for action, entry in selected["actions"].items():
|
| 5230 |
lines += ["### " + action,
|
| 5231 |
"State: " + states[action]["state"] + "."
|
|
|
|
| 5237 |
lines.append("Previous name: `" + entry["legacy_name"] + "`.")
|
| 5238 |
schema = copy.deepcopy(entry["schema"])
|
| 5239 |
schema.get("properties", {}).pop("about", None)
|
| 5240 |
+
schema, collapsed = external_tools.guide_schema(schema)
|
| 5241 |
+
uses_filter_node = uses_filter_node or collapsed
|
| 5242 |
lines += ["```json", json.dumps(_mcp_schema_copy(schema), ensure_ascii=True, indent=2), "```", ""]
|
| 5243 |
+
if uses_filter_node:
|
| 5244 |
+
lines += [external_tools.filter_node_guide(), ""]
|
| 5245 |
return _MCPGuideText("\n".join(lines) + "\n")
|
| 5246 |
lines += ["## Connected AI clients", "",
|
| 5247 |
"Client names and who connected them in this workspace. No entries means none are connected.",
|
|
|
|
| 5372 |
return reply
|
| 5373 |
params = req.get("params")
|
| 5374 |
params = params if isinstance(params, dict) else {}
|
| 5375 |
+
arguments = _mcp_hoist_call_metadata(params.get("name"), params.get("arguments", {}))
|
| 5376 |
+
tool, schema = _mcp_audit_schema(params.get("name"), arguments)
|
| 5377 |
+
limitation_tool, limitation_action = _mcp_limitation_address(tool, arguments)
|
| 5378 |
try:
|
| 5379 |
with external_activity.capture_call(session, tool) as call:
|
| 5380 |
if tool == limitation_tool:
|
| 5381 |
external_activity.note_action(limitation_action)
|
| 5382 |
+
external_activity.note_arguments(arguments, schema)
|
| 5383 |
metadata = params.get("_meta")
|
| 5384 |
call["question"] = metadata.get("loopable/question") if isinstance(metadata, dict) else None
|
| 5385 |
reply = _dispatch_mcp(req, session, base_url)
|
|
|
|
| 5459 |
return value
|
| 5460 |
|
| 5461 |
|
| 5462 |
+
def _mcp_hoist_call_metadata(name, arguments):
|
| 5463 |
+
"""Return group call arguments with intent, about and purpose lifted out of the inner arguments."""
|
| 5464 |
+
import tool_groups
|
| 5465 |
+
keys = ("intent", "about", "purpose")
|
| 5466 |
+
if (not isinstance(name, str) or name not in tool_groups.groups() or not isinstance(arguments, dict)
|
| 5467 |
+
or not isinstance(arguments.get("arguments"), dict)
|
| 5468 |
+
or not any(key in arguments["arguments"] for key in keys)):
|
| 5469 |
+
return arguments
|
| 5470 |
+
inner = arguments["arguments"]
|
| 5471 |
+
hoisted = {**arguments, "arguments": {key: value for key, value in inner.items() if key not in keys}}
|
| 5472 |
+
# The value beside action and arguments wins over the nested copy.
|
| 5473 |
+
for key in keys:
|
| 5474 |
+
if key in inner and key not in arguments:
|
| 5475 |
+
hoisted[key] = inner[key]
|
| 5476 |
+
return hoisted
|
| 5477 |
+
|
| 5478 |
+
|
| 5479 |
def _mcp_requires_intent(name, arguments):
|
| 5480 |
"""Classify declared writes before argument validation can mask the intent requirement."""
|
| 5481 |
if name == "confirm_change":
|
|
|
|
| 5550 |
return {"jsonrpc": "2.0", "id": rid, "result": {"contents": [resource]}}
|
| 5551 |
if method != "tools/call":
|
| 5552 |
return protocol_error(rid, -32601, "The requested MCP method was not found.")
|
| 5553 |
+
arguments = _mcp_hoist_call_metadata(name, params.get("arguments", {}))
|
| 5554 |
intent = _mcp_call_intent(arguments)
|
| 5555 |
if intent is None and _mcp_requires_intent(name, arguments):
|
| 5556 |
raise err(400, "call_intent_required", "Send intent explaining why you are making this write.",
|
|
|
|
| 5573 |
purpose = _build_purpose(arguments.pop("purpose"))
|
| 5574 |
if "about" in metadata_keys:
|
| 5575 |
about = arguments.pop("about")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5576 |
_assert_tool_query_filter_bounds(name, arguments)
|
| 5577 |
resolved = tool_groups.resolve(name, arguments)
|
| 5578 |
confirm = True
|
api/routes_query.py
CHANGED
|
@@ -124,6 +124,18 @@ QUERY_NO_SOURCE_MATCHED = (
|
|
| 124 |
"None of the databases you can read cover that question. Pick one from the list, "
|
| 125 |
"or ask about a database you can open."
|
| 126 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
QUERY_DRAFT_ADMIN = "This database has no approved fields yet. Pick the ones this answer should use and they will be approved for everyone."
|
| 128 |
QUERY_DRAFT_MEMBER = "This database has no approved fields yet. Pick the ones you need and your administrators will be asked to approve them."
|
| 129 |
QUERY_DRAFT_SENT = "Sent to your administrators. Ask again once one of them approves."
|
|
@@ -1023,6 +1035,8 @@ def _call_model(question, snapshot, model=MODEL_AUTO, chat=None, history=None, s
|
|
| 1023 |
tools.extend(agent_runtime.tool_specs(session, snapshot=snapshot))
|
| 1024 |
if turn.get("openWork"):
|
| 1025 |
tools = [tool for tool in tools if tool["function"]["name"] == "open_items"]
|
|
|
|
|
|
|
| 1026 |
if turn.get("admittedTools"):
|
| 1027 |
tools = [tool for tool in tools if tool["function"]["name"] in set(turn["admittedTools"])]
|
| 1028 |
if turn.get("memoryOnly"):
|
|
@@ -1033,6 +1047,11 @@ def _call_model(question, snapshot, model=MODEL_AUTO, chat=None, history=None, s
|
|
| 1033 |
"You are the Loopable Assistant. Use tools for facts. Writes run at once. Deletes need the user's yes.")
|
| 1034 |
if turn.get("context"):
|
| 1035 |
prompt += "\n\n" + turn["context"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1036 |
if turn.get("toolShareRequests"):
|
| 1037 |
prompt += ("\nThis turn concerns a pending tool-share approval only. Use the prior conversation to identify "
|
| 1038 |
"the request. Ask which request when the user's approval is ambiguous. "
|
|
@@ -2013,8 +2032,13 @@ def _submit_active(body, session, question, selected_model, context_hint, dock,
|
|
| 2013 |
memory_only = dock is None and not target and replay is None and assistant_memory.admits(question)
|
| 2014 |
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 {
|
| 2015 |
"database": target, "auto": False, "alternatives": []}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2016 |
target = routed["database"]
|
| 2017 |
-
route_refusal = (None if dock is not None or open_work or admitted or memory_only or share_requests or agent_runtime.has_attachments() else
|
| 2018 |
QUERY_NO_SOURCE_MATCHED if not target and replay is None else routed.get("refusal"))
|
| 2019 |
|
| 2020 |
# Snapshot turns plan mirrors from schema. Dock turns read through permissioned tools.
|
|
@@ -2064,6 +2088,9 @@ def _submit_active(body, session, question, selected_model, context_hint, dock,
|
|
| 2064 |
turn["admittedTools"] = sorted(admitted)
|
| 2065 |
if memory_only:
|
| 2066 |
turn["memoryOnly"] = True
|
|
|
|
|
|
|
|
|
|
| 2067 |
turn["memoryCompanyRequested"] = assistant_memory.company_requested(question)
|
| 2068 |
if snapshot is not None:
|
| 2069 |
turn["memorySources"] = [{"database": snapshot["database"],
|
|
@@ -2872,6 +2899,32 @@ def _route_candidates(session):
|
|
| 2872 |
return candidates
|
| 2873 |
|
| 2874 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2875 |
def _route(session, question):
|
| 2876 |
from harness import semantic as sem
|
| 2877 |
candidates = _route_candidates(session)
|
|
@@ -3438,6 +3491,10 @@ def governed_query(body: dict = Body(default=None),
|
|
| 3438 |
"database": "", "label": "", "reason": "", "auto": False, "alternatives": []}}
|
| 3439 |
routed = _route(session, question) if not database else {
|
| 3440 |
"database": database, "label": "", "reason": "", "auto": False, "alternatives": []}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3441 |
database = routed["database"]
|
| 3442 |
if database:
|
| 3443 |
_semantic_authorize(session, database, require_answerable=not routed["auto"])
|
|
|
|
| 124 |
"None of the databases you can read cover that question. Pick one from the list, "
|
| 125 |
"or ask about a database you can open."
|
| 126 |
)
|
| 127 |
+
# A fresh turn made only of these words names no data subject, so it is conversation (D-2673).
|
| 128 |
+
_CHAT_WORDS = (
|
| 129 |
+
"hello hi hey hiya good morning afternoon evening thanks thank please ok okay yes no yeah yep sure "
|
| 130 |
+
"cool great nice sorry bye goodbye cheers welcome i me you your yours we it its they them can could "
|
| 131 |
+
"would will should might have has had be am been being does doing done get got there here then "
|
| 132 |
+
"just also too so really still now hear see know help think say ask mean understand need want like "
|
| 133 |
+
"try talk chat explain database table field data workspace loopable assistant loopy app question answer"
|
| 134 |
+
)
|
| 135 |
+
CONVERSATION_PROMPT = (
|
| 136 |
+
"\nNo database is chosen for this turn and no tool is available. Reply in plain sentences with no "
|
| 137 |
+
"markdown, and never state a figure from data. If the user asks about their data, ask which database to use."
|
| 138 |
+
)
|
| 139 |
QUERY_DRAFT_ADMIN = "This database has no approved fields yet. Pick the ones this answer should use and they will be approved for everyone."
|
| 140 |
QUERY_DRAFT_MEMBER = "This database has no approved fields yet. Pick the ones you need and your administrators will be asked to approve them."
|
| 141 |
QUERY_DRAFT_SENT = "Sent to your administrators. Ask again once one of them approves."
|
|
|
|
| 1035 |
tools.extend(agent_runtime.tool_specs(session, snapshot=snapshot))
|
| 1036 |
if turn.get("openWork"):
|
| 1037 |
tools = [tool for tool in tools if tool["function"]["name"] == "open_items"]
|
| 1038 |
+
if turn.get("conversation"):
|
| 1039 |
+
tools = []
|
| 1040 |
if turn.get("admittedTools"):
|
| 1041 |
tools = [tool for tool in tools if tool["function"]["name"] in set(turn["admittedTools"])]
|
| 1042 |
if turn.get("memoryOnly"):
|
|
|
|
| 1047 |
"You are the Loopable Assistant. Use tools for facts. Writes run at once. Deletes need the user's yes.")
|
| 1048 |
if turn.get("context"):
|
| 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. "
|
|
|
|
| 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"]
|
| 2041 |
+
route_refusal = (None if conversation or dock is not None or open_work or admitted or memory_only or share_requests or agent_runtime.has_attachments() else
|
| 2042 |
QUERY_NO_SOURCE_MATCHED if not target and replay is None else routed.get("refusal"))
|
| 2043 |
|
| 2044 |
# Snapshot turns plan mirrors from schema. Dock turns read through permissioned tools.
|
|
|
|
| 2088 |
turn["admittedTools"] = sorted(admitted)
|
| 2089 |
if memory_only:
|
| 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 |
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:
|
| 2908 |
+
projection = getattr(session.runtime, "get_projection", None)
|
| 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):
|
| 2929 |
from harness import semantic as sem
|
| 2930 |
candidates = _route_candidates(session)
|
|
|
|
| 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.
|
| 3496 |
+
return {"status": "continue_chat", "routedTo": {
|
| 3497 |
+
"database": "", "label": "", "reason": "", "auto": False, "alternatives": []}}
|
| 3498 |
database = routed["database"]
|
| 3499 |
if database:
|
| 3500 |
_semantic_authorize(session, database, require_answerable=not routed["auto"])
|
platform/core/external_tools.py
CHANGED
|
@@ -140,6 +140,46 @@ _QUERY_FILTER = {"oneOf": [
|
|
| 140 |
_object({"link": _STRING, "where": _query_filter_node(allow_link=False)},
|
| 141 |
("link", "where"), additionalProperties=False),
|
| 142 |
]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
_BINDING = _object({
|
| 144 |
"database": _STRING,
|
| 145 |
"aggregate": _object({"fn": _STRING, "field": _STRING, "metric_key": _STRING}),
|
|
|
|
| 140 |
_object({"link": _STRING, "where": _query_filter_node(allow_link=False)},
|
| 141 |
("link", "where"), additionalProperties=False),
|
| 142 |
]}
|
| 143 |
+
FILTER_NODE_REF = "#/$defs/filter_node"
|
| 144 |
+
FILTER_NODE_EXAMPLE = {"conj": "and", "nodes": [
|
| 145 |
+
{"colId": "status", "op": "eq", "value": "open"},
|
| 146 |
+
{"conj": "or", "children": [{"colId": "amount", "op": "gt", "value": 100},
|
| 147 |
+
{"colId": "region", "op": "eq", "value": "West"}]},
|
| 148 |
+
]}
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def _is_filter_node(value):
|
| 152 |
+
"""Tell a published query filter node from any other schema."""
|
| 153 |
+
branches = value.get("oneOf") if isinstance(value, dict) and set(value) == {"oneOf"} else None
|
| 154 |
+
first = branches[0] if isinstance(branches, list) and branches and isinstance(branches[0], dict) else {}
|
| 155 |
+
properties = first.get("properties")
|
| 156 |
+
return isinstance(properties, dict) and "colId" in properties and "op" in properties
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def guide_schema(schema):
|
| 160 |
+
"""Return a guide copy with each query filter node replaced by one reference, and whether any was."""
|
| 161 |
+
if _is_filter_node(schema):
|
| 162 |
+
return {"$ref": FILTER_NODE_REF}, True
|
| 163 |
+
if isinstance(schema, list):
|
| 164 |
+
pairs = [guide_schema(item) for item in schema]
|
| 165 |
+
return [item for item, _ in pairs], any(used for _, used in pairs)
|
| 166 |
+
if not isinstance(schema, dict):
|
| 167 |
+
return copy.deepcopy(schema), False
|
| 168 |
+
pairs = {key: guide_schema(child) for key, child in schema.items()}
|
| 169 |
+
return {key: item for key, (item, _) in pairs.items()}, any(used for _, used in pairs.values())
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def filter_node_guide():
|
| 173 |
+
"""Return the one markdown section that defines the filter_node reference in a guide."""
|
| 174 |
+
node = {"oneOf": [guide_schema(branch)[0] for branch in _QUERY_FILTER_NODE["oneOf"]]}
|
| 175 |
+
return ("## filter_node\n\n"
|
| 176 |
+
"A filter_node is a condition {colId, op, ...}, a group {conj, children: 1 to 50 filter_node}, "
|
| 177 |
+
"or a link {link, where}.\n"
|
| 178 |
+
"Groups nest at most two deep inside one node. A link's where holds no link.\n"
|
| 179 |
+
"Example filter: `" + json.dumps(FILTER_NODE_EXAMPLE, ensure_ascii=True) + "`\n"
|
| 180 |
+
"```json\n" + json.dumps({"$defs": {"filter_node": node}}, ensure_ascii=True, indent=2) + "\n```")
|
| 181 |
+
|
| 182 |
+
|
| 183 |
_BINDING = _object({
|
| 184 |
"database": _STRING,
|
| 185 |
"aggregate": _object({"fn": _STRING, "field": _STRING, "metric_key": _STRING}),
|
web/public/AIOS_DEPLOY_RECEIPT
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
2d96a99b0c54d87dc083b47e8e4ff618efe36834f406dd1763eb68aef932f525
|