SPB Git

Repository Public

inbox.py 4.8 KB 84 lines python

1#!/usr/bin/env python32# SP Notes Core3# File: Scripts/recorders/inbox.py4# Description: Records the fixtures of capture and inbox: every capture kind (2.x kinds, and what the server answers to5#              the 3.0 ones), the inbox list and badge, the six triage actions with their undo, and the Smart Inbox6#              routes of the AI workstream as this server answers them.7#8# Author: Simon-Pierre Boucher9# Contact: contact@spboucher.ai10import base641112from _parity_support import ParityRecorder, new_id1314r = ParityRecorder("inbox")15PNG = base64.b64decode("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==")161718def cap(body, save, headers=None):19    reply = r.call("POST", "/api/capture", body, save=save, headers=headers)20    if reply.status in (200, 201):21        r.track(reply.json["id"])22    return reply.json232425note = cap({"kind": "note", "text": "Fixture · idée parity\nPremière ligne\nDeuxième ligne"}, "capture-note")26todo = cap({"kind": "tasks", "text": "Fixture · appeler la banque\nFixture · signer l'offre"}, "capture-tasks")27link = cap({"kind": "link", "url": "https://example.org/article", "text": "Fixture · article parity"}, "capture-link")28att = r.form("POST", "/api/attachments", {"id": new_id()}, "file", "fixture-parity.png", PNG, "image/png").json29photo = cap({"kind": "photo", "attachmentIds": [att["id"]]}, "capture-photo")30att2 = r.form("POST", "/api/attachments", {"id": new_id()}, "file", "fixture-parity.txt", b"Fixture parity file\n", "text/plain").json31filecap = cap({"kind": "file", "text": "Fixture · fichier parity", "attachmentIds": [att2["id"]]}, "capture-file")32att3 = r.form("POST", "/api/attachments", {"id": new_id()}, "file", "fixture-parity.m4a", b"\x00\x00\x00\x1cftypM4A \x00\x00\x00\x00M4A mp42isom\x00\x00\x00\x00", "audio/mp4").json33audio = cap({"kind": "audio", "attachmentIds": [att3["id"]]}, "capture-audio")34key = "spn-fixture-" + new_id()35replay1 = cap({"kind": "note", "text": "Fixture · rejouée parity"}, "capture-keyed", headers={"Idempotency-Key": key})36cap({"kind": "note", "text": "Fixture · rejouée parity"}, "capture-keyed-replay", headers={"Idempotency-Key": key})37for kind in ("screenshot", "selection", "document"):38    cap({"kind": kind, "text": "Fixture · 3.0 " + kind}, "capture-next-" + kind)39cap({"kind": "note"}, "capture-empty")40cap({"kind": "link", "text": "pas une adresse"}, "capture-link-no-url")41cap({"kind": "photo", "attachmentIds": [new_id()]}, "capture-unknown-attachment")4243r.call("GET", "/api/inbox", save="inbox-list")44r.call("GET", "/api/inbox?count=1", save="inbox-count")4546# Smart Inbox (AI workstream): recorded as this server answers. `cachedOnly=1` never calls a provider.47r.call("GET", "/api/inbox/%s/suggestions?cachedOnly=1" % note["id"], save="suggestions-cached-only")48r.call("POST", "/api/inbox/%s/apply" % note["id"], {}, save="apply-nothing")4950parent = r.page("Classeur parity", section="projects")51host = r.page("Base inbox parity", type="database", section="databases")52db = r.call("GET", "/api/databases/" + host["id"]).json535455def triage(page, body, name):56    reply = r.call("POST", "/api/inbox/" + page["id"], body, save="triage-" + name)57    return reply.json585960kept = triage(note, {"action": "keep", "section": "projects", "parentId": parent["id"]}, "keep")61r.call("POST", "/api/inbox/" + note["id"], {"action": "archive"}, save="triage-not-in-inbox")62r.call("POST", "/api/inbox/undo", {"actionId": kept["actionId"]}, save="undo")63r.call("POST", "/api/inbox/undo", {"actionId": kept["actionId"]}, save="undo-again")64r.call("POST", "/api/inbox/undo", {"actionId": new_id()}, save="undo-not-found")65tasked = triage(todo, {"action": "task", "dueAt": "2026-12-01T15:00:00.000Z", "priority": "high"}, "task")66rowed = triage(link, {"action": "database", "databaseId": db["id"]}, "database")67refd = triage(filecap, {"action": "reference"}, "reference")68triage(photo, {"action": "archive"}, "archive")69trashed = triage(audio, {"action": "trash"}, "trash")70r.call("POST", "/api/inbox/" + replay1["id"], {"action": "snooze"}, save="triage-validation")71r.call("POST", "/api/inbox/" + replay1["id"], {"action": "database", "databaseId": new_id()}, save="triage-database-not-found")72r.call("POST", "/api/inbox/" + new_id(), {"action": "archive"}, save="triage-page-not-found")73r.call("POST", "/api/inbox/" + replay1["id"], {"action": "keep", "section": "databases"}, save="triage-bad-section")74r.call("GET", "/api/inbox", save="inbox-list-after")7576# Clean-up of what the triage created.77for row in r.call("GET", "/api/databases/%s/rows" % db["id"]).json:78    r.track(row["pageId"])79for action in (tasked, rowed, refd, trashed):80    r.call("POST", "/api/inbox/undo", {"actionId": action["actionId"]})81for attachment in (att, att2, att3):82    r.call("DELETE", "/api/attachments?id=" + attachment["id"])83r.finish()84
Files main
Menu

Theme