Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:33:44 +08:00

46 lines
1.8 KiB
Python

"""Translate a plain note into SurfSense's document-ingestion envelope.
The REST API ingests free text through the browser-extension document shape
(title + page content + visit metadata); the backend then chunks and embeds it
like any saved page. Isolating that mapping lets the KB tool offer a simple
title+content surface without leaking the envelope's shape.
"""
from __future__ import annotations
import re
from datetime import datetime, timezone
def build_note_document(
*, workspace_id: int, title: str, content: str, source_url: str | None
) -> dict:
"""Wrap a note in the EXTENSION document payload the create endpoint expects."""
# ponytail: reuses the extension-ingestion path to add free text. Ceiling —
# visit metadata is synthesized; the "real page URL" is a stable synthetic
# link derived from the title. Upgrade path: a first-class note endpoint.
captured_at = datetime.now(timezone.utc).isoformat()
return {
"document_type": "EXTENSION",
"workspace_id": workspace_id,
"content": [
{
"metadata": {
"BrowsingSessionId": "surfsense-mcp",
"VisitedWebPageURL": source_url or _synthetic_url(title),
"VisitedWebPageTitle": title,
"VisitedWebPageDateWithTimeInISOString": captured_at,
"VisitedWebPageReffererURL": "",
"VisitedWebPageVisitDurationInMilliseconds": "0",
},
"pageContent": content,
}
],
}
def _synthetic_url(title: str) -> str:
slug = re.sub(r"[^a-z0-9]+", "-", title.casefold()).strip("-") or "note"
stamp = datetime.now(timezone.utc).strftime("%Y%m%d%H%M%S")
return f"https://surfsense.local/mcp-note/{slug}-{stamp}"