mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-08 20:25:19 +02:00
Merge upstream/dev
This commit is contained in:
commit
8bdfd00a15
191 changed files with 3301 additions and 4079 deletions
|
|
@ -114,8 +114,8 @@ async def build_new_chat_input_state(
|
|||
|
||||
final_query = _render_query_with_context(
|
||||
agent_user_query=agent_user_query,
|
||||
recent_reports=recent_reports,
|
||||
mentioned_connectors=mentioned_connectors,
|
||||
recent_reports=recent_reports,
|
||||
)
|
||||
|
||||
if thread_visibility == ChatVisibility.SEARCH_SPACE and current_user_display_name:
|
||||
|
|
@ -198,44 +198,11 @@ async def _resolve_mentions_for_query(
|
|||
return agent_user_query, accepted_folder_ids
|
||||
|
||||
|
||||
def _render_connector_block(mentioned_connectors: list[dict[str, Any]]) -> str | None:
|
||||
"""Render the ``<mentioned_connectors>`` block, or ``None`` when empty.
|
||||
|
||||
Malformed entries (non-dict, or missing id/type) are skipped.
|
||||
"""
|
||||
connector_lines: list[str] = []
|
||||
for connector in mentioned_connectors:
|
||||
if not isinstance(connector, dict):
|
||||
continue
|
||||
connector_id = connector.get("id")
|
||||
connector_type = connector.get("connector_type") or connector.get(
|
||||
"document_type"
|
||||
)
|
||||
account_name = connector.get("account_name") or connector.get("title")
|
||||
if connector_id is None or connector_type is None:
|
||||
continue
|
||||
connector_lines.append(
|
||||
f' - connector_id={connector_id}, connector_type="{connector_type}", '
|
||||
f'account_name="{account_name or ""}"'
|
||||
)
|
||||
if not connector_lines:
|
||||
return None
|
||||
return (
|
||||
"<mentioned_connectors>\n"
|
||||
"The user selected these exact connector accounts with @. "
|
||||
"These entries are selection metadata, not retrieved connector content. "
|
||||
"When a connector-backed tool needs an account, use the matching "
|
||||
"connector_id from this list if the tool supports connector_id:\n"
|
||||
+ "\n".join(connector_lines)
|
||||
+ "\n</mentioned_connectors>"
|
||||
)
|
||||
|
||||
|
||||
def _render_query_with_context(
|
||||
*,
|
||||
agent_user_query: str,
|
||||
recent_reports: list[Report],
|
||||
mentioned_connectors: list[dict[str, Any]] | None,
|
||||
recent_reports: list[Report],
|
||||
) -> str:
|
||||
"""Prepend the ``<mentioned_connectors>`` then ``<report_context>`` blocks.
|
||||
|
||||
|
|
@ -243,10 +210,9 @@ def _render_query_with_context(
|
|||
"""
|
||||
context_parts: list[str] = []
|
||||
|
||||
if mentioned_connectors:
|
||||
connector_block = _render_connector_block(mentioned_connectors)
|
||||
if connector_block:
|
||||
context_parts.append(connector_block)
|
||||
connector_context = _render_mentioned_connectors(mentioned_connectors)
|
||||
if connector_context:
|
||||
context_parts.append(connector_context)
|
||||
|
||||
if recent_reports:
|
||||
report_lines: list[str] = []
|
||||
|
|
@ -272,3 +238,40 @@ def _render_query_with_context(
|
|||
return f"{context}\n\n<user_query>{agent_user_query}</user_query>"
|
||||
|
||||
return agent_user_query
|
||||
|
||||
|
||||
def _render_mentioned_connectors(
|
||||
mentioned_connectors: list[dict[str, Any]] | None,
|
||||
) -> str | None:
|
||||
"""Render selected connector account metadata for connector-backed tools."""
|
||||
if not mentioned_connectors:
|
||||
return None
|
||||
|
||||
connector_lines: list[str] = []
|
||||
for connector in mentioned_connectors:
|
||||
if not isinstance(connector, dict):
|
||||
continue
|
||||
connector_id = connector.get("id")
|
||||
connector_type = connector.get("connector_type") or connector.get(
|
||||
"document_type"
|
||||
)
|
||||
account_name = connector.get("account_name") or connector.get("title")
|
||||
if connector_id is None or connector_type is None:
|
||||
continue
|
||||
connector_lines.append(
|
||||
f' - connector_id={connector_id}, connector_type="{connector_type}", '
|
||||
f'account_name="{account_name or ""}"'
|
||||
)
|
||||
|
||||
if not connector_lines:
|
||||
return None
|
||||
|
||||
return (
|
||||
"<mentioned_connectors>\n"
|
||||
"The user selected these exact connector accounts with @. "
|
||||
"These entries are selection metadata, not retrieved connector content. "
|
||||
"When a connector-backed tool needs an account, use the matching "
|
||||
"connector_id from this list if the tool supports connector_id:\n"
|
||||
+ "\n".join(connector_lines)
|
||||
+ "\n</mentioned_connectors>"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue