6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
"""Render resolved references into a ``<referenced_this_turn>`` pointer block.
|
|
|
|
Pointers, not content: each line names what the user referenced and how to
|
|
reach it (a path, a connector handle, a title) so the model knows what to
|
|
retrieve from. Actual content is pulled later via tools, never injected here.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from .models import (
|
|
ChatReference,
|
|
ConnectorReference,
|
|
DocumentReference,
|
|
FolderReference,
|
|
Reference,
|
|
)
|
|
|
|
_HEADER = (
|
|
"The user pointed at these with @ this turn. They are scope, not content "
|
|
"— when the question is about them, retrieve from them before answering."
|
|
)
|
|
|
|
|
|
def render_reference_pointers(references: list[Reference]) -> str | None:
|
|
"""Render references as one read-only pointer block.
|
|
|
|
Returns ``None`` when there is nothing to render so callers can skip the
|
|
block entirely.
|
|
"""
|
|
if not references:
|
|
return None
|
|
|
|
lines = [_render_pointer(reference) for reference in references]
|
|
return (
|
|
"<referenced_this_turn>\n"
|
|
f"{_HEADER}\n" + "\n".join(lines) + "\n</referenced_this_turn>"
|
|
)
|
|
|
|
|
|
def _render_pointer(reference: Reference) -> str:
|
|
"""One ``- {kind} {id} — {handle}`` line, shaped per kind."""
|
|
head = f"- {reference.kind.value} {reference.entity_id} — "
|
|
return head + _handle(reference)
|
|
|
|
|
|
def _handle(reference: Reference) -> str:
|
|
"""The human-reachable handle: a path, a connector provider, or a title."""
|
|
label = _clean(reference.label)
|
|
match reference:
|
|
case DocumentReference() | FolderReference():
|
|
return f'"{label}" ({reference.path})'
|
|
case ConnectorReference():
|
|
provider = _clean(reference.provider) if reference.provider else ""
|
|
return f"{provider} ({label})" if provider else label
|
|
case ChatReference():
|
|
return f'"{label}"'
|
|
|
|
|
|
def _clean(text: str) -> str:
|
|
"""Collapse whitespace so a title can't break the one-line pointer."""
|
|
return " ".join(text.split())
|
|
|
|
|
|
__all__ = ["render_reference_pointers"]
|