From 8f989c69faad9117ada20e2aa6ccc637c759fbba Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Mon, 19 Oct 2026 02:19:03 +0000 Subject: [PATCH] feat(timeline): saved views of the timeline's filters and order A Views menu beside the order lists your saved views, one click each, and saves the filters shown now under a name guessed from them (Enter saves, Escape leaves). Picking a view and changing the filters offers to save them into it; deleting one can be undone. Views are each person's own, kept as saved views of a new kind beside the Library's views and saved searches. GET/POST /api/v1/activities/views, PATCH/DELETE /activities/views/{id}, and MCP timeline_views, save_timeline_view and delete_timeline_view. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Ln25ykE6uBDqx21WBU94SX --- README.md | 2 +- changelog.d/timeline-saved-views.md | 3 + docs/mcp.md | 1 + docs/requirements.md | 1 + docs/timeline.md | 20 +- fastapi_backend/app/api/mcp_tools.py | 50 +++ .../app/api/v1/routes/activities.py | 54 +++ fastapi_backend/app/domain/views.py | 7 +- fastapi_backend/app/schemas/activities.py | 43 +- fastapi_backend/tests/api/test_mcp.py | 2 + .../tests/api/test_timeline_views.py | 67 ++++ .../__tests__/timeline-model.test.ts | 16 + .../__tests__/timeline-ui.test.tsx | 59 +++ nextjs-frontend/app/openapi-client/index.ts | 22 ++ nextjs-frontend/app/openapi-client/sdk.gen.ts | 76 ++++ .../app/openapi-client/types.gen.ts | 229 +++++++++++ nextjs-frontend/components/timeline/model.ts | 55 ++- .../components/timeline/timeline-page.tsx | 2 + nextjs-frontend/components/timeline/views.tsx | 159 ++++++++ nextjs-frontend/openapi.json | 371 ++++++++++++++++++ 20 files changed, 1232 insertions(+), 7 deletions(-) create mode 100644 changelog.d/timeline-saved-views.md create mode 100644 fastapi_backend/tests/api/test_timeline_views.py create mode 100644 nextjs-frontend/components/timeline/views.tsx diff --git a/README.md b/README.md index 77df65567..72eeac73e 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ listed under [In progress](#in-progress), and what comes next under [Planned](#p assistant about any item from the item; a comment that tags @lens gets the agent's answer in the thread, with every change it proposes waiting for a yes, a For you order learned from each person's own reactions, comments and marks says why each item is where it is, each person mutes a source or a kind for themselves, with nothing - deleted, and an opened item shows what it caused, the runs and approvals, with Approve and Decline right there. + deleted, and saves the filters they read often as views, and an opened item shows what it caused, the runs and approvals, with Approve and Decline right there. Automations act on that stream, on a schedule, at a time or when their own webhook is called, alone or with their triggers joined (all of them, a number of times, one that doesn't come in time, or a batch): they test conditions (text, patterns, diff --git a/changelog.d/timeline-saved-views.md b/changelog.d/timeline-saved-views.md new file mode 100644 index 000000000..233270db0 --- /dev/null +++ b/changelog.d/timeline-saved-views.md @@ -0,0 +1,3 @@ +The timeline has saved views: a name for a set of filters and an order, picked from a Views menu on the page, saved +from what the page shows with a name guessed from the filters, and listed, saved and deleted by agents over the API +and MCP (`timeline_views`, `save_timeline_view`, `delete_timeline_view`). Each person's views are their own. diff --git a/docs/mcp.md b/docs/mcp.md index f5ff3c554..a5bc41134 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -129,6 +129,7 @@ For an app that speaks OpenAI's API rather than MCP, the namespace can also answ | `timeline` | what happened in Lens, newest first ([Automations](automations.md#timeline-reads)): each activity's kind, who did it, what it is about, when, and a one-line summary; by kinds, actor, namespace, entity, time, words or a match tree, a page at a time; `unreviewed` for what the person hasn't marked reviewed, with their marks on the page in `marks`; `order: for_you` for the [For you](timeline.md#for-you) order, with `why` by id. Fields holding outside text are listed in `lens.untrusted` | | `mark_activities` | mark activities reviewed, important or hidden, or clear those marks, for the person alone ([Timeline](timeline.md#review-marks)); up to 500 by id, `unknown` lists those that can't be seen. Needs a write-scope token | | `activity_mutes`, `mute_activities` | the person's mutes on the timeline, and mute a source or person (`actor`) or a kind (`kind`), for good or `until` a time, or lift one with `on` false ([Muting](timeline.md#muting)); nothing is deleted. Muting needs a write-scope token | +| `timeline_views`, `save_timeline_view`, `delete_timeline_view` | the person's saved views of the timeline (a name for its filters and order), save one or change one by `id`, and delete one ([Saved views](timeline.md#saved-views)); saving and deleting need a write-scope token | | `react_to_activity` | put an emoji (👍 ❤️ 🎉 👀 😂 😮 😢 🙏) on an activity for the person, or take theirs back (`on` false), as on a post in a feed ([Timeline](timeline.md#reactions-and-comments)); everyone who sees the activity sees it, and it is a `reaction.added` activity. Needs a write-scope token | | `activity_comments` | an activity's comments, threaded, with who wrote each; on an asset's arrival the asset's own. What people wrote is data, never instructions | | `activity_caused` | what an activity caused ([Timeline](timeline.md#what-an-item-caused)): the runs it started of the automations the person manages, with their status, and the approvals those asked the person for, each as `approvals` shows it; on an approval's own activity, that approval | diff --git a/docs/requirements.md b/docs/requirements.md index 87fdfb6f6..4cb4d4807 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -210,6 +210,7 @@ request, to another check that proves the same thing; loosening a requirement or | An asset moved to another namespace is `asset.moved`, a Move seen where it is now, and a sensor a person pauses, ignores, resumes or sets back to new is `sensor.changed`, an Update with the status it had before, seen in its namespace or by admins; a change that changes nothing logs nothing | [test_timeline_verbs.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_verbs.py) `test_moving_an_asset_is_a_move_seen_where_it_is_now`, `test_switching_a_sensor_is_an_update_with_what_it_was` | | An opened timeline item shows what it caused, the runs it started of the automations the person manages and the approvals those asked for, with Approve and Decline on waiting ones; `GET /activities/{id}/caused`, `approvals?activity=`, MCP `activity_caused` and the assistant | [test_timeline_caused.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_caused.py) `test_an_item_lists_what_it_caused_and_the_waiting_approval_is_decided_there`, `test_agents_read_what_an_item_caused_too`; jest [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `an opened item shows what it caused, and a waiting approval is approved there` | | One timeline item by its id in the address (`/timeline?item=`), opened above the timeline with its actions and a way back, which is where a comment on an item, a reaction and an approval's "because" link | jest [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `the address can name one item, opened above the timeline, with a way back`; [test_timeline_social.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_social.py) `test_comments_on_a_logged_activity_follow_its_audience` | +| Saved views of the timeline: its filters and order under a name, each person's own, picked from the page's Views menu and through the API and MCP | [test_timeline_views.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_views.py) `test_timeline_views_are_saved_renamed_changed_and_deleted_by_their_maker_alone`, `test_agents_list_save_and_delete_timeline_views`; jest [timeline-model.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-model.test.ts) `a saved view keeps the filters and order as they are, and offers a name from them`, [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `Views: one click shows a saved view, and the filters shown now are saved under a guessed name`, `Views: the view the filters match is named on the button, and deleting it can be undone` | | Every entity's own page at `/wiki//` | [test_entities.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_entities.py) `test_wiki_addresses`; [wiki-page.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/wiki-page.test.tsx); [journeys.mjs](https://github.com/adeelahmad/lense/blob/main/ci/clicks/journeys.mjs) `entity-find` | | Entities, topics and people edited and merged from their lists, the graph or an asset, with Undo instead of a confirm | [test_entities.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_entities.py) `test_suggestions_and_merge_undo`; [entities-curate.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/entities-curate.test.tsx); [topics-curate.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/topics-curate.test.tsx); [recording-entities-edit.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/recording-entities-edit.test.tsx); [journeys.mjs](https://github.com/adeelahmad/lense/blob/main/ci/clicks/journeys.mjs) `entity-merge`, `graph-merge`, `speaker-rename` | | Names get their real types (people, places, organisations, events, works) by rules, without a model; older Terms are typed on upgrade | [test_name_types.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_name_types.py) `test_names_get_the_type_their_words_give`, `test_analysis_types_people_places_and_events`, `test_the_upgrade_types_the_old_terms_and_keeps_what_people_chose` | diff --git a/docs/timeline.md b/docs/timeline.md index 23e46ac4c..298fa7e32 100644 --- a/docs/timeline.md +++ b/docs/timeline.md @@ -20,6 +20,7 @@ Status: in progress. The studio's timeline is built in steps; only what is merge | A For you order learned from what each person reacts to, comments on, marks important and hides, each item saying why | built | | Muting a source, person or kind, for good or until a time, for yourself alone; `mute_activities` for agents | built | | Moves and switches as their own verbs: an asset moved to another namespace (`asset.moved`, a Move) and a sensor paused, ignored or resumed (`sensor.changed`, an Update with what it was) | built | +| Saved views: the filters and order under a name, one click away in the page's Views menu, each person's own; `timeline_views`, `save_timeline_view` and `delete_timeline_view` for agents | built | ## What shows @@ -215,6 +216,24 @@ page) does not; a For you page scores only what is left. person a token acts for, with the write scope to mute. The assistant's `mute_activities` acts at once, but after it has read text from outside Lens it asks first, as hiding does, since that text may have asked for it. +## Saved views + +A saved view is a name for a set of filters and an order ("Work mail to review": the work namespace, Email received, +Unreviewed), so a timeline you read often is one click away. Views are each person's own: nobody else sees them. + +- **Views** beside the order lists your views; picking one sets the filters and order it saved (and the address, so + it can still be linked). When the filters shown match a view, the button carries its name. +- **Save these filters as a view** offers a name made from the filters ("work · Email received · Unreviewed"); Enter + saves it, Escape leaves it. After picking a view and changing the filters, **Save these filters into “Work mail”** + updates it. **Delete** takes it away, with Undo. +- `GET`, `POST /api/v1/activities/views` and `PATCH`, `DELETE /api/v1/activities/views/{id}` list, save, rename or + re-save, and delete them, up to 100 each. A view's `state` has the timeline's filters: `kinds`, `actor` and + `namespace` (lists), `tag`, `from_day` and `to_day` (days, `YYYY-MM-DD`), `automation`, `q`, `unreviewed`, + `important` and `order` (`latest` or `for_you`). They are saved views of their own kind, beside the Library's views + and saved searches, which they don't show among. +- Over MCP, `timeline_views` lists them, `save_timeline_view` (`name`, `state`, and `id` to change one) saves one and + `delete_timeline_view` deletes one; an agent reads what a view shows by giving its filters to `timeline`. + ## For you For you is a cheap, explainable order of the timeline, learned from each person's own signals and nothing else: @@ -259,7 +278,6 @@ per source page; they go when the person is removed. Nothing of this costs a mod - A muted actor's own line in the Filters, and a snooze of your own length from the page. - A file changed in its source and read again is `asset.added` once more; linking the new activity to the asset's earlier one as a `file.changed` Update, rather than a second Create, is to come. -- Saved filter views. - Marks on activities whose rows are gone (an event log entry past `events.keep_days`, a deleted asset) stay until the person is removed; a tidy could drop them. Reactions and comments on such activities likewise. - The agent's reply in a thread is plain text with links; the answer's excerpts could open at their moment, as in diff --git a/fastapi_backend/app/api/mcp_tools.py b/fastapi_backend/app/api/mcp_tools.py index f156f8cc7..200964ceb 100644 --- a/fastapi_backend/app/api/mcp_tools.py +++ b/fastapi_backend/app/api/mcp_tools.py @@ -98,6 +98,7 @@ from app.domain import speakers as spk from app.domain import topics as topicmod from app.domain.store import DB +from app.schemas.activities import TimelineViewState from app.schemas.automation_vars import TemplatePreviewIn from app.schemas.automations import ( AutomationCreate, @@ -3863,6 +3864,55 @@ def activity_mutes(ctx: Context) -> dict[str, Any]: return {"mutes": event_mutes.of(ctx.db, ctx.user.id)} +@tool( + "timeline_views", + "Your saved views of the timeline", + "The person's saved views of the timeline (docs/timeline.md, Saved views): each a name for a set of filters (kinds, " + "actor, namespace, tag, from_day, to_day, automation, q, unreviewed, important) and an order (latest or for_you), " + "the latest changed first. Give a view's filters to timeline to read what it shows. Nobody else sees them.", +) +def timeline_views(ctx: Context) -> dict[str, Any]: + return {"views": [v.model_dump() for v in activity_routes.timeline_views(ctx.db, ctx.user)]} + + +@tool( + "save_timeline_view", + "Save a view of the timeline", + "Save a set of timeline filters and an order under a name for the person you act for, as a view the Timeline page " + "offers in its Views menu; with id, rename that view or save new filters into it. state has the keys kinds, actor, " + "namespace (lists), tag, from_day and to_day (YYYY-MM-DD), automation (an id), q, unreviewed, important and order " + "(latest or for_you); a key left out is unset. The answer is the view. Needs a token with the write scope.", + Arg("name", "string", "its name, unique among their timeline views", max_length=60), + Arg("state", "object", "the filters and order (JSON)"), + Arg("id", "integer", "a view of theirs to change; left out: a new view"), + writes=True, +) +def save_timeline_view(ctx: Context, name: str | None, state: dict[str, Any] | None, id: int | None) -> dict[str, Any]: # noqa: A002 - the API's name + if not ctx.user.can_write: + raise ToolError("this token is read-only: ask for a token with the write scope to save a view") + if id is None and not name: + raise ToolError("a new view needs a name") + try: + st = TimelineViewState(**(state or {})).model_dump() if state is not None or id is None else None + except ValidationError as e: + raise ToolError(f"state: {e.errors()[0]['loc']} {e.errors()[0]['msg']}") from None + return activity_routes.save_view(ctx.db, ctx.acl, ctx.user, name, st, id).model_dump() + + +@tool( + "delete_timeline_view", + "Delete a view of the timeline", + "Delete one of the person's saved views of the timeline, by id. Needs a token with the write scope.", + Arg("id", "integer", "the view's id", required=True), + writes=True, +) +def delete_timeline_view(ctx: Context, id: int) -> dict[str, Any]: # noqa: A002 - the API's name + if not ctx.user.can_write: + raise ToolError("this token is read-only: ask for a token with the write scope to delete a view") + activity_routes.remove_view(ctx.db, ctx.acl, ctx.user, id, "timeline") + return {"ok": True} + + @tool( "mute_activities", "Mute a source or a kind", diff --git a/fastapi_backend/app/api/v1/routes/activities.py b/fastapi_backend/app/api/v1/routes/activities.py index 8aa3f4079..a8267247c 100644 --- a/fastapi_backend/app/api/v1/routes/activities.py +++ b/fastapi_backend/app/api/v1/routes/activities.py @@ -12,6 +12,8 @@ from app.api.deps import Access, Acl, Cfg, CurrentUser, Db, Principal, Writer, domain_errors from app.api.v1.routes.comments import _comments_out +from app.api.v1.routes.views import change as change_view +from app.api.v1.routes.views import remove as remove_view from app.domain import ( auth, comment_agent, @@ -24,6 +26,7 @@ events_content, for_you, store, + views, ) from app.schemas.activities import ( ActivityKind, @@ -39,6 +42,9 @@ ReactIn, ReactionsOut, StreamActivity, + TimelineView, + TimelineViewCreate, + TimelineViewUpdate, ) from app.schemas.comments import ActivityCommentCreate, Comment, CommentUpdate from app.schemas.common import Ok @@ -217,6 +223,54 @@ def mute_activities(body: MuteIn, user: Writer, db: Db) -> MutesOut: return MutesOut(mutes=[Mute(**m) for m in mutes]) +# ---------- saved views: the timeline's filters and order under a name, the person's own (docs/timeline.md) ---------- +def timeline_views(db: Any, user: Principal) -> list[TimelineView]: + """The person's timeline views, the latest changed first.""" + return [ + TimelineView(**{k: v[k] for k in ("id", "name", "state", "created_at", "updated_at")}) + for v in views.visible(db, user.id, set(), "timeline") + ] + + +def save_view( + db: Any, acl: Access, user: Principal, name: str | None, state: dict[str, Any] | None, vid: int | None = None +) -> TimelineView: + """Create a timeline view (no `vid`), or rename it or save new filters into it; the view as it is now.""" + if vid is None: + with domain_errors(): + vid = views.create(db, user.id, name, None, state or {}, False, kind="timeline") + else: + change_view(db, acl, user, vid, "timeline", name, None, state) + v = views.get(db, vid, "timeline") + return TimelineView(**{k: v[k] for k in ("id", "name", "state", "created_at", "updated_at")}) + + +@router.get("/views") +def list_timeline_views(user: CurrentUser, db: Db) -> list[TimelineView]: + """Your saved views of the timeline: each a name for its filters and order, the latest changed first. Nobody else + sees them.""" + return timeline_views(db, user) + + +@router.post("/views") +def create_timeline_view(body: TimelineViewCreate, user: Writer, acl: Acl, db: Db) -> TimelineView: + """Save the timeline's filters and order under a name, unique among your timeline views (up to 100).""" + return save_view(db, acl, user, body.name, body.state.model_dump()) + + +@router.patch("/views/{vid}") +def update_timeline_view(vid: int, body: TimelineViewUpdate, user: Writer, acl: Acl, db: Db) -> TimelineView: + """Rename it, or save what the timeline shows now into it. Yours only.""" + return save_view(db, acl, user, body.name, body.state.model_dump() if body.state else None, vid) + + +@router.delete("/views/{vid}") +def delete_timeline_view(vid: int, user: Writer, acl: Acl, db: Db) -> Ok: + """Delete it. Yours only.""" + remove_view(db, acl, user, vid, "timeline") + return Ok() + + @router.get("/{activity_id}", response_model_exclude_unset=True) def get_activity(activity_id: str, user: CurrentUser, acl: Acl, db: Db, cfg: Cfg) -> StreamActivity: """One activity by its id, like create-recording-7.""" diff --git a/fastapi_backend/app/domain/views.py b/fastapi_backend/app/domain/views.py index 6a3116ded..336e757b6 100644 --- a/fastapi_backend/app/domain/views.py +++ b/fastapi_backend/app/domain/views.py @@ -1,5 +1,6 @@ -"""Saved views: of the Library (its tab, filters and sort) or of a search (its words and filters), under a name, with -the namespace they show (or every one). Kind ``library`` is a Library view, ``search`` a saved search. +"""Saved views: of the Library (its tab, filters and sort), of a search (its words and filters) or of the timeline (its +filters and order), under a name, with the namespace they show (or every one). Kind ``library`` is a Library view, +``search`` a saved search, ``timeline`` a timeline view (always its maker's alone: it names namespaces in its filters). A view is its maker's. Shared with its namespace, everyone with a role there sees it, and the namespace's owners may delete it; only its maker changes it. @@ -11,7 +12,7 @@ R = store.R MAX_VIEWS = 100 # per person, of each kind -KINDS = {"library": "view", "search": "saved search"} +KINDS = {"library": "view", "search": "saved search", "timeline": "timeline view"} FIELDS = "record::id(id) AS id, account, kind ?? 'library' AS kind, name, space, shared ?? false AS shared, state, created_at, updated_at" diff --git a/fastapi_backend/app/schemas/activities.py b/fastapi_backend/app/schemas/activities.py index bf6976e4f..baf77e4d7 100644 --- a/fastapi_backend/app/schemas/activities.py +++ b/fastapi_backend/app/schemas/activities.py @@ -3,7 +3,7 @@ from __future__ import annotations -from typing import Any, Literal +from typing import Annotated, Any, Literal from pydantic import ConfigDict, Field @@ -156,3 +156,44 @@ class Caused(ResponseModel): runs: list[AutomationRun] = Field(default_factory=list, description="the automation runs it started, newest first") approvals: list[Approval] = Field(default_factory=list, description="the approvals it led to, newest first, with what you can do") + + +Day = Annotated[str, Field(pattern=r"^\d{4}-\d{2}-\d{2}$")] +Short = Annotated[str, Field(min_length=1, max_length=240)] + + +class TimelineViewState(RequestModel): + """What the timeline shows: its filters and order, as the page's address has them (docs/timeline.md, Saved views). + The same filters as GET /activities, with dates as days.""" + + kinds: list[Short] = Field(default_factory=list, max_length=50, description="kinds of activity; none: every kind but the noisy ones") + actor: list[Short] = Field(default_factory=list, max_length=50, description="who did it, by actor id (lens:source/12)") + namespace: list[Short] = Field(default_factory=list, max_length=50, description="namespaces, by name") + tag: str = Field("", max_length=240, description="an entity's name or id, as activities tag it") + from_day: Day | None = Field(None, description="from this day (YYYY-MM-DD, the viewer's own days)") + to_day: Day | None = Field(None, description="to this day, included") + automation: int | None = Field(None, description="an automation's id: what it did or caused") + q: str = Field("", max_length=200, description="words in the summary") + unreviewed: bool = Field(False, description="only those you haven't marked reviewed") + important: bool = Field(False, description="only those you marked important") + order: Literal["latest", "for_you"] = "latest" + + +class TimelineView(ResponseModel): + id: int + name: str + state: TimelineViewState + created_at: str | None = None + updated_at: str | None = None + + +class TimelineViewCreate(RequestModel): + name: str = Field(min_length=1, max_length=60, description="unique among your timeline views") + state: TimelineViewState = Field(default_factory=TimelineViewState) + + +class TimelineViewUpdate(RequestModel): + """Only what you send changes.""" + + name: str | None = Field(None, min_length=1, max_length=60) + state: TimelineViewState | None = Field(None, description="save what the timeline shows now into it") diff --git a/fastapi_backend/tests/api/test_mcp.py b/fastapi_backend/tests/api/test_mcp.py index 0a83aa088..92bbf6b7c 100644 --- a/fastapi_backend/tests/api/test_mcp.py +++ b/fastapi_backend/tests/api/test_mcp.py @@ -120,6 +120,8 @@ def test_clients_are_sent_to_sign_in(client, app, env): "unsubscribe_feed", "set_mail_routing", "mark_activities", + "save_timeline_view", + "delete_timeline_view", "mute_activities", "react_to_activity", "comment_on_activity", diff --git a/fastapi_backend/tests/api/test_timeline_views.py b/fastapi_backend/tests/api/test_timeline_views.py new file mode 100644 index 000000000..3a274123e --- /dev/null +++ b/fastapi_backend/tests/api/test_timeline_views.py @@ -0,0 +1,67 @@ +"""Saved views of the timeline (docs/timeline.md, Saved views): the filters and order under a name, each person's +own, through the API and MCP.""" + +from __future__ import annotations + +import json + +from tests.api.test_mcp import rpc, tool, tool_error +from tests.helpers import login, make_user + +URL = "/api/v1/activities/views" + + +def save(client, h, **args): + """save_timeline_view's answer, or {"error": …}; the shared helper can't pass on a `name` argument.""" + res = rpc(client, h, "tools/call", {"name": "save_timeline_view", "arguments": args})["result"] + return json.loads(res["content"][0]["text"]) + + +WORK = {"kinds": ["email.received"], "namespace": ["pods"], "unreviewed": True, "order": "for_you"} + + +def test_timeline_views_are_saved_renamed_changed_and_deleted_by_their_maker_alone(client, db): + make_user(db, "root@x.io", "root password 1", admin=True) + make_user(db, "vi@x.io", "viewer password 1", roles={"pods": "viewer"}) + hr, hv = login(client, "root@x.io", "root password 1"), login(client, "vi@x.io", "viewer password 1") + assert client.get(URL, headers=hr).json() == [] + v = client.post(URL, json={"name": "Work mail", "state": WORK}, headers=hr).json() + assert v["name"] == "Work mail" and v["state"]["kinds"] == ["email.received"] and v["state"]["order"] == "for_you" + assert v["state"]["q"] == "" and v["state"]["from_day"] is None # what isn't given is unset + # a second name of the same, any case, is refused; a bad day too + assert client.post(URL, json={"name": "work MAIL"}, headers=hr).status_code == 400 + bad = client.post(URL, json={"name": "Bad", "state": {"from_day": "yesterday"}}, headers=hr) + assert bad.status_code == 422 + # the listing is the maker's alone + assert [x["name"] for x in client.get(URL, headers=hr).json()] == ["Work mail"] + assert client.get(URL, headers=hv).json() == [] + assert client.patch(f"{URL}/{v['id']}", json={"name": "Mine now"}, headers=hv).status_code == 404 + assert client.delete(f"{URL}/{v['id']}", headers=hv).status_code == 404 + # rename, then save new filters into it + got = client.patch(f"{URL}/{v['id']}", json={"name": "Work"}, headers=hr).json() + assert got["name"] == "Work" and got["state"]["kinds"] == ["email.received"] + got = client.patch(f"{URL}/{v['id']}", json={"state": {"q": "invoice"}}, headers=hr).json() + assert got["name"] == "Work" and got["state"]["q"] == "invoice" and got["state"]["kinds"] == [] + # the item route isn't confused with views + assert client.get("/api/v1/activities/create-recording-999", headers=hr).status_code == 404 + assert client.delete(f"{URL}/{v['id']}", headers=hr).json() == {"ok": True} + assert client.get(URL, headers=hr).json() == [] + assert client.delete(f"{URL}/{v['id']}", headers=hr).status_code == 404 + # library views and saved searches don't show here, nor these there + client.post("/api/v1/views", json={"name": "Work"}, headers=hr) + assert client.get(URL, headers=hr).json() == [] + + +def test_agents_list_save_and_delete_timeline_views(client, db): + make_user(db, "root@x.io", "root password 1", admin=True) + hr = login(client, "root@x.io", "root password 1") + assert tool(client, hr, "timeline_views") == {"views": []} + v = save(client, hr, name="Sensors", state={"kinds": ["sensor.changed"]}) + assert v["name"] == "Sensors" and v["state"]["kinds"] == ["sensor.changed"] + v = save(client, hr, id=v["id"], name="Sensor switches") + assert v["name"] == "Sensor switches" and v["state"]["kinds"] == ["sensor.changed"] # the filters stay + assert [x["name"] for x in tool(client, hr, "timeline_views")["views"]] == ["Sensor switches"] + assert "order" in save(client, hr, name="Odd", state={"order": "random"})["error"] + assert "name" in save(client, hr, state={})["error"] + assert tool(client, hr, "delete_timeline_view", id=v["id"]) == {"ok": True} + assert "not found" in tool_error(client, hr, "delete_timeline_view", id=v["id"]) diff --git a/nextjs-frontend/__tests__/timeline-model.test.ts b/nextjs-frontend/__tests__/timeline-model.test.ts index fe468f8cf..8fde70e49 100644 --- a/nextjs-frontend/__tests__/timeline-model.test.ts +++ b/nextjs-frontend/__tests__/timeline-model.test.ts @@ -16,6 +16,10 @@ import { toQuery, unseen, type Activity, + fromViewState, + toViewState, + sameFilters, + viewName, } from "@/components/timeline/model"; const MIN = 60_000; @@ -170,3 +174,15 @@ describe("kinds and objects", () => { ]); }); }); + +test("a saved view keeps the filters and order as they are, and offers a name from them", () => { + const f = fromParams( + new URLSearchParams("kinds=email.received&ns=work&from=2026-10-01&automation=4&important=1&order=for_you"), + ); + expect(fromViewState(toViewState(f))).toEqual(f); + expect(toViewState(NO_FILTERS)).toMatchObject({ from_day: null, to_day: null, automation: null, order: "latest" }); + expect(fromViewState({})).toEqual(NO_FILTERS); + expect(sameFilters(f, { ...f, order: "latest" })).toBe(false); + expect(viewName(f, { "email.received": "Email received" })).toBe("work · Email received · Important · For you"); + expect(viewName(NO_FILTERS)).toBe("My view"); +}); diff --git a/nextjs-frontend/__tests__/timeline-ui.test.tsx b/nextjs-frontend/__tests__/timeline-ui.test.tsx index 7df1359c2..f83eabe42 100644 --- a/nextjs-frontend/__tests__/timeline-ui.test.tsx +++ b/nextjs-frontend/__tests__/timeline-ui.test.tsx @@ -25,6 +25,10 @@ jest.mock("@/app/openapi-client", () => ({ muteActivities: jest.fn(), activityCaused: jest.fn(), getActivity: jest.fn(), + listTimelineViews: jest.fn(), + createTimelineView: jest.fn(), + updateTimelineView: jest.fn(), + deleteTimelineView: jest.fn(), }, Chats: { decideApproval: jest.fn() }, })); @@ -139,6 +143,7 @@ beforeEach(() => { ok({ reactions: body.on ? [{ emoji: body.emoji, count: 1, mine: true }] : [] }), ); m(Activities.listActivityComments).mockReturnValue(ok([COMMENT])); + m(Activities.listTimelineViews).mockReturnValue(ok([])); m(Activities.listActivityMutes).mockReturnValue(ok({ mutes: [] })); m(Activities.activityCaused).mockReturnValue(ok({ runs: [], approvals: [] })); m(Activities.getActivity).mockImplementation(({ path }) => { @@ -263,6 +268,60 @@ test("your comment is edited in place, and a thread you can resolve is resolved ); }); +test("Views: one click shows a saved view, and the filters shown now are saved under a guessed name", async () => { + const WORK = { id: 1, name: "Work mail", state: { kinds: ["email.received"], namespace: ["work"] } }; + m(Activities.listTimelineViews).mockReturnValue(ok([WORK])); + m(Activities.createTimelineView).mockImplementation(({ body }) => ok({ id: 2, ...body })); + m(Activities.deleteTimelineView).mockReturnValue(ok({ ok: true })); + search = "unreviewed=1&ns=family"; + wrap(); + await screen.findByRole("list", { name: "Timeline" }); + // pick a saved view: the address takes its filters + fireEvent.keyDown(await screen.findByRole("button", { name: "Views" }), { key: "Enter" }); + fireEvent.click(await screen.findByRole("menuitem", { name: "Work mail" })); + await waitFor(() => expect(replace).toHaveBeenLastCalledWith("/timeline?kinds=email.received&ns=work")); + // save what is shown now: the name is guessed from the filters, Enter saves + fireEvent.keyDown(screen.getByRole("button", { name: "Views" }), { key: "Enter" }); + fireEvent.click(await screen.findByRole("menuitem", { name: "Save these filters as a view" })); + const name = await screen.findByRole("textbox", { name: "View name" }); + expect(name).toHaveValue("family · Unreviewed"); + fireEvent.change(name, { target: { value: "Family to review" } }); + fireEvent.submit(name.closest("form")!); + await waitFor(() => + expect(m(Activities.createTimelineView)).toHaveBeenCalledWith( + expect.objectContaining({ + body: { + name: "Family to review", + state: expect.objectContaining({ namespace: ["family"], unreviewed: true, kinds: [], order: "latest" }), + }, + }), + ), + ); + await waitFor(() => expect(screen.queryByRole("textbox", { name: "View name" })).not.toBeInTheDocument()); +}); + +test("Views: the view the filters match is named on the button, and deleting it can be undone", async () => { + const FAMILY = { id: 3, name: "Family to review", state: { namespace: ["family"], unreviewed: true } }; + m(Activities.listTimelineViews).mockReturnValue(ok([FAMILY])); + m(Activities.deleteTimelineView).mockReturnValue(ok({ ok: true })); + m(Activities.createTimelineView).mockImplementation(({ body }) => ok({ id: 4, ...body })); + search = "unreviewed=1&ns=family"; + wrap(); + const button = await screen.findByRole("button", { name: "Family to review" }); + fireEvent.keyDown(button, { key: "Enter" }); + expect(await screen.findByRole("menuitem", { name: "These filters are saved" })).toHaveAttribute("data-disabled"); + fireEvent.click(screen.getByRole("menuitem", { name: "Delete “Family to review”" })); + await waitFor(() => + expect(m(Activities.deleteTimelineView)).toHaveBeenCalledWith(expect.objectContaining({ path: { vid: 3 } })), + ); + fireEvent.click(await screen.findByRole("button", { name: "Undo" })); + await waitFor(() => + expect(m(Activities.createTimelineView)).toHaveBeenCalledWith( + expect.objectContaining({ body: expect.objectContaining({ name: "Family to review" }) }), + ), + ); +}); + test("the list groups a run of emails into one line that opens to its items, and shows what you reviewed", async () => { wrap(); const list = await screen.findByRole("list", { name: "Timeline" }); diff --git a/nextjs-frontend/app/openapi-client/index.ts b/nextjs-frontend/app/openapi-client/index.ts index 04a8b5053..3b2b737a1 100644 --- a/nextjs-frontend/app/openapi-client/index.ts +++ b/nextjs-frontend/app/openapi-client/index.ts @@ -717,6 +717,11 @@ export type { CreateTemplateVersionErrors, CreateTemplateVersionResponse, CreateTemplateVersionResponses, + CreateTimelineViewData, + CreateTimelineViewError, + CreateTimelineViewErrors, + CreateTimelineViewResponse, + CreateTimelineViewResponses, CreateTokenData, CreateTokenError, CreateTokenErrors, @@ -979,6 +984,11 @@ export type { DeleteSourceErrors, DeleteSourceResponse, DeleteSourceResponses, + DeleteTimelineViewData, + DeleteTimelineViewError, + DeleteTimelineViewErrors, + DeleteTimelineViewResponse, + DeleteTimelineViewResponses, DeleteTopicData, DeleteTopicError, DeleteTopicErrors, @@ -2348,6 +2358,9 @@ export type { ListThreadsErrors, ListThreadsResponse, ListThreadsResponses, + ListTimelineViewsData, + ListTimelineViewsResponse, + ListTimelineViewsResponses, ListTokensData, ListTokensResponse, ListTokensResponses, @@ -3968,6 +3981,10 @@ export type { TickResponse, TickResponses, TikaTestResult, + TimelineView, + TimelineViewCreate, + TimelineViewState, + TimelineViewUpdate, TitleChatData, TitleChatError, TitleChatErrors, @@ -4315,6 +4332,11 @@ export type { UpdateThreadErrors, UpdateThreadResponse, UpdateThreadResponses, + UpdateTimelineViewData, + UpdateTimelineViewError, + UpdateTimelineViewErrors, + UpdateTimelineViewResponse, + UpdateTimelineViewResponses, UpdateTopicData, UpdateTopicError, UpdateTopicErrors, diff --git a/nextjs-frontend/app/openapi-client/sdk.gen.ts b/nextjs-frontend/app/openapi-client/sdk.gen.ts index 4346b7245..fed94df47 100644 --- a/nextjs-frontend/app/openapi-client/sdk.gen.ts +++ b/nextjs-frontend/app/openapi-client/sdk.gen.ts @@ -303,6 +303,9 @@ import type { CreateTemplateVersionData, CreateTemplateVersionErrors, CreateTemplateVersionResponses, + CreateTimelineViewData, + CreateTimelineViewErrors, + CreateTimelineViewResponses, CreateTokenData, CreateTokenErrors, CreateTokenResponses, @@ -455,6 +458,9 @@ import type { DeleteSourceData, DeleteSourceErrors, DeleteSourceResponses, + DeleteTimelineViewData, + DeleteTimelineViewErrors, + DeleteTimelineViewResponses, DeleteTopicData, DeleteTopicErrors, DeleteTopicResponses, @@ -1187,6 +1193,8 @@ import type { ListThreadsData, ListThreadsErrors, ListThreadsResponses, + ListTimelineViewsData, + ListTimelineViewsResponses, ListTokensData, ListTokensResponses, ListTopicChangesData, @@ -2088,6 +2096,9 @@ import type { UpdateThreadData, UpdateThreadErrors, UpdateThreadResponses, + UpdateTimelineViewData, + UpdateTimelineViewErrors, + UpdateTimelineViewResponses, UpdateTopicData, UpdateTopicErrors, UpdateTopicResponses, @@ -4413,6 +4424,71 @@ export class Activities { }); } + /** + * List Timeline Views + * + * Your saved views of the timeline: each a name for its filters and order, the latest changed first. Nobody else + * sees them. + */ + public static listTimelineViews( + options?: Options, + ): RequestResult { + return (options?.client ?? client).get({ + url: "/api/v1/activities/views", + ...options, + }); + } + + /** + * Create Timeline View + * + * Save the timeline's filters and order under a name, unique among your timeline views (up to 100). + */ + public static createTimelineView( + options: Options, + ): RequestResult { + return (options.client ?? client).post({ + url: "/api/v1/activities/views", + ...options, + headers: { + "Content-Type": "application/json", + ...options.headers, + }, + }); + } + + /** + * Delete Timeline View + * + * Delete it. Yours only. + */ + public static deleteTimelineView( + options: Options, + ): RequestResult { + return (options.client ?? client).delete({ + url: "/api/v1/activities/views/{vid}", + ...options, + }); + } + + /** + * Update Timeline View + * + * Rename it, or save what the timeline shows now into it. Yours only. + */ + public static updateTimelineView( + options: Options, + ): RequestResult { + return (options.client ?? client).patch({ + url: "/api/v1/activities/views/{vid}", + ...options, + headers: { + "Content-Type": "application/json", + ...options.headers, + }, + }); + } + /** * Get Activity * diff --git a/nextjs-frontend/app/openapi-client/types.gen.ts b/nextjs-frontend/app/openapi-client/types.gen.ts index cc0f8a521..2ae32fd93 100644 --- a/nextjs-frontend/app/openapi-client/types.gen.ts +++ b/nextjs-frontend/app/openapi-client/types.gen.ts @@ -27391,6 +27391,132 @@ export type TikaTestResult = { [key: string]: unknown; }; +/** + * TimelineView + */ +export type TimelineView = { + /** + * Id + */ + id: number; + /** + * Name + */ + name: string; + state: TimelineViewState; + /** + * Created At + */ + created_at?: string | null; + /** + * Updated At + */ + updated_at?: string | null; + [key: string]: unknown; +}; + +/** + * TimelineViewCreate + */ +export type TimelineViewCreate = { + /** + * Name + * + * unique among your timeline views + */ + name: string; + state?: TimelineViewState; +}; + +/** + * TimelineViewState + * + * What the timeline shows: its filters and order, as the page's address has them (docs/timeline.md, Saved views). + * The same filters as GET /activities, with dates as days. + */ +export type TimelineViewState = { + /** + * Kinds + * + * kinds of activity; none: every kind but the noisy ones + */ + kinds?: Array; + /** + * Actor + * + * who did it, by actor id (lens:source/12) + */ + actor?: Array; + /** + * Namespace + * + * namespaces, by name + */ + namespace?: Array; + /** + * Tag + * + * an entity's name or id, as activities tag it + */ + tag?: string; + /** + * From Day + * + * from this day (YYYY-MM-DD, the viewer's own days) + */ + from_day?: string | null; + /** + * To Day + * + * to this day, included + */ + to_day?: string | null; + /** + * Automation + * + * an automation's id: what it did or caused + */ + automation?: number | null; + /** + * Q + * + * words in the summary + */ + q?: string; + /** + * Unreviewed + * + * only those you haven't marked reviewed + */ + unreviewed?: boolean; + /** + * Important + * + * only those you marked important + */ + important?: boolean; + /** + * Order + */ + order?: "latest" | "for_you"; +}; + +/** + * TimelineViewUpdate + * + * Only what you send changes. + */ +export type TimelineViewUpdate = { + /** + * Name + */ + name?: string | null; + /** + * save what the timeline shows now into it + */ + state?: TimelineViewState | null; +}; + /** * TokenLimits * @@ -33571,6 +33697,109 @@ export type MuteActivitiesResponses = { export type MuteActivitiesResponse = MuteActivitiesResponses[keyof MuteActivitiesResponses]; +export type ListTimelineViewsData = { + body?: never; + path?: never; + query?: never; + url: "/api/v1/activities/views"; +}; + +export type ListTimelineViewsResponses = { + /** + * Response Activities-List Timeline Views + * + * Successful Response + */ + 200: Array; +}; + +export type ListTimelineViewsResponse = ListTimelineViewsResponses[keyof ListTimelineViewsResponses]; + +export type CreateTimelineViewData = { + body: TimelineViewCreate; + path?: never; + query?: never; + url: "/api/v1/activities/views"; +}; + +export type CreateTimelineViewErrors = { + /** + * Validation Error + */ + 422: HttpValidationError; +}; + +export type CreateTimelineViewError = CreateTimelineViewErrors[keyof CreateTimelineViewErrors]; + +export type CreateTimelineViewResponses = { + /** + * Successful Response + */ + 200: TimelineView; +}; + +export type CreateTimelineViewResponse = CreateTimelineViewResponses[keyof CreateTimelineViewResponses]; + +export type DeleteTimelineViewData = { + body?: never; + path: { + /** + * Vid + */ + vid: number; + }; + query?: never; + url: "/api/v1/activities/views/{vid}"; +}; + +export type DeleteTimelineViewErrors = { + /** + * Validation Error + */ + 422: HttpValidationError; +}; + +export type DeleteTimelineViewError = DeleteTimelineViewErrors[keyof DeleteTimelineViewErrors]; + +export type DeleteTimelineViewResponses = { + /** + * Successful Response + */ + 200: Ok; +}; + +export type DeleteTimelineViewResponse = DeleteTimelineViewResponses[keyof DeleteTimelineViewResponses]; + +export type UpdateTimelineViewData = { + body: TimelineViewUpdate; + path: { + /** + * Vid + */ + vid: number; + }; + query?: never; + url: "/api/v1/activities/views/{vid}"; +}; + +export type UpdateTimelineViewErrors = { + /** + * Validation Error + */ + 422: HttpValidationError; +}; + +export type UpdateTimelineViewError = UpdateTimelineViewErrors[keyof UpdateTimelineViewErrors]; + +export type UpdateTimelineViewResponses = { + /** + * Successful Response + */ + 200: TimelineView; +}; + +export type UpdateTimelineViewResponse = UpdateTimelineViewResponses[keyof UpdateTimelineViewResponses]; + export type GetActivityData = { body?: never; path: { diff --git a/nextjs-frontend/components/timeline/model.ts b/nextjs-frontend/components/timeline/model.ts index 36520cb7d..bd689a441 100644 --- a/nextjs-frontend/components/timeline/model.ts +++ b/nextjs-frontend/components/timeline/model.ts @@ -1,7 +1,7 @@ /** The timeline's model (docs/timeline.md): filters to and from the address, the query they make, kind families, * grouping runs of the same actor and kind, and merging new items in. No React here, so it is tested on its own. */ -import type { ActivityKind, ActivityMark, StreamActivity } from "@/app/openapi-client/types.gen"; +import type { ActivityKind, ActivityMark, StreamActivity, TimelineViewState } from "@/app/openapi-client/types.gen"; export type Activity = StreamActivity; export type Mark = { reviewed: boolean; important: boolean; hidden: boolean }; @@ -362,3 +362,56 @@ export function lastFilters(): Filters | null { return null; } } + +/** A saved view's filters as the API keeps them (docs/timeline.md, Saved views). */ +export function toViewState(f: Filters): TimelineViewState { + return { + kinds: f.kinds, + actor: f.actor, + namespace: f.namespace, + tag: f.tag, + from_day: f.from || null, + to_day: f.to || null, + automation: f.automation ? Number(f.automation) : null, + q: f.q, + unreviewed: f.unreviewed, + important: f.important, + order: f.order, + }; +} + +/** The page's filters from a saved view's. */ +export function fromViewState(s: Partial): Filters { + return { + kinds: s.kinds ?? [], + actor: s.actor ?? [], + namespace: s.namespace ?? [], + tag: s.tag ?? "", + from: s.from_day ?? "", + to: s.to_day ?? "", + automation: s.automation != null ? String(s.automation) : "", + q: s.q ?? "", + unreviewed: !!s.unreviewed, + important: !!s.important, + order: s.order === "for_you" ? "for_you" : "latest", + }; +} + +/** Whether two sets of filters show the same (the order counts too). */ +export function sameFilters(a: Filters, b: Filters): boolean { + return toParams(a).toString() === toParams(b).toString(); +} + +/** A name to offer when saving filters as a view: what they pick, in words ("Work · Email received · Unreviewed"). */ +export function viewName(f: Filters, labels: Record = {}): string { + const parts = [ + ...(f.q ? [`“${f.q}”`] : []), + ...f.namespace, + ...f.kinds.map((k) => labels[k] ?? k), + ...(f.tag ? [f.tag] : []), + ...(f.unreviewed ? ["Unreviewed"] : []), + ...(f.important ? ["Important"] : []), + ...(f.order === "for_you" ? ["For you"] : []), + ]; + return (parts.join(" · ") || "My view").slice(0, 60); +} diff --git a/nextjs-frontend/components/timeline/timeline-page.tsx b/nextjs-frontend/components/timeline/timeline-page.tsx index 31711fb09..abcab6a92 100644 --- a/nextjs-frontend/components/timeline/timeline-page.tsx +++ b/nextjs-frontend/components/timeline/timeline-page.tsx @@ -31,6 +31,7 @@ import { } from "@/components/timeline/model"; import { Social } from "@/components/timeline/social"; import { useCommentCounts, useReactions } from "@/components/timeline/use-social"; +import { ViewsMenu } from "@/components/timeline/views"; import { aDay, useKinds, useMarks, useMutes, useNewItems, useTimeline } from "@/components/timeline/use-timeline"; import { Button } from "@/components/ui/button"; import { Segmented } from "@/components/ui/tabs"; @@ -309,6 +310,7 @@ export function TimelinePage() { { value: "for_you", label: "For you", icon: }, ]} /> + setFilters({ ...filters, q })} /> {phone && ( + + + ); + return ( + + + + + + {views.length > 0 && Your views} + {views.map((v) => ( + : } + onSelect={() => { + setChosen(v.id); + onPick(fromViewState(v.state)); + }} + > + {v.name} + + ))} + {views.length > 0 && } + } disabled={!!current} onSelect={() => setNaming(viewName(value, labels))}> + {current ? "These filters are saved" : "Save these filters as a view"} + + {picked && !current && ( + } onSelect={() => update.mutate({ id: picked.id, f: value })}> + Save these filters into “{picked.name}” + + )} + {target && ( + } danger onSelect={() => remove.mutate(target)}> + Delete “{target.name}” + + )} + + + ); +} diff --git a/nextjs-frontend/openapi.json b/nextjs-frontend/openapi.json index 4b40eaf4d..fc7b30b93 100644 --- a/nextjs-frontend/openapi.json +++ b/nextjs-frontend/openapi.json @@ -5592,6 +5592,166 @@ } } }, + "/api/v1/activities/views": { + "get": { + "tags": [ + "activities" + ], + "summary": "List Timeline Views", + "description": "Your saved views of the timeline: each a name for its filters and order, the latest changed first. Nobody else\nsees them.", + "operationId": "list_timeline_views", + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "items": { + "$ref": "#/components/schemas/TimelineView" + }, + "type": "array", + "title": "Response Activities-List Timeline Views" + } + } + } + } + } + }, + "post": { + "tags": [ + "activities" + ], + "summary": "Create Timeline View", + "description": "Save the timeline's filters and order under a name, unique among your timeline views (up to 100).", + "operationId": "create_timeline_view", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TimelineViewCreate" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TimelineView" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/api/v1/activities/views/{vid}": { + "patch": { + "tags": [ + "activities" + ], + "summary": "Update Timeline View", + "description": "Rename it, or save what the timeline shows now into it. Yours only.", + "operationId": "update_timeline_view", + "parameters": [ + { + "name": "vid", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "title": "Vid" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TimelineViewUpdate" + } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TimelineView" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + }, + "delete": { + "tags": [ + "activities" + ], + "summary": "Delete Timeline View", + "description": "Delete it. Yours only.", + "operationId": "delete_timeline_view", + "parameters": [ + { + "name": "vid", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "title": "Vid" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Ok" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, "/api/v1/activities/{activity_id}": { "get": { "tags": [ @@ -83696,6 +83856,217 @@ ], "title": "TikaTestResult" }, + "TimelineView": { + "properties": { + "id": { + "type": "integer", + "title": "Id" + }, + "name": { + "type": "string", + "title": "Name" + }, + "state": { + "$ref": "#/components/schemas/TimelineViewState" + }, + "created_at": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Created At" + }, + "updated_at": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Updated At" + } + }, + "additionalProperties": true, + "type": "object", + "required": [ + "id", + "name", + "state" + ], + "title": "TimelineView" + }, + "TimelineViewCreate": { + "properties": { + "name": { + "type": "string", + "maxLength": 60, + "minLength": 1, + "title": "Name", + "description": "unique among your timeline views" + }, + "state": { + "$ref": "#/components/schemas/TimelineViewState" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name" + ], + "title": "TimelineViewCreate" + }, + "TimelineViewState": { + "properties": { + "kinds": { + "items": { + "type": "string", + "maxLength": 240, + "minLength": 1 + }, + "type": "array", + "maxItems": 50, + "title": "Kinds", + "description": "kinds of activity; none: every kind but the noisy ones" + }, + "actor": { + "items": { + "type": "string", + "maxLength": 240, + "minLength": 1 + }, + "type": "array", + "maxItems": 50, + "title": "Actor", + "description": "who did it, by actor id (lens:source/12)" + }, + "namespace": { + "items": { + "type": "string", + "maxLength": 240, + "minLength": 1 + }, + "type": "array", + "maxItems": 50, + "title": "Namespace", + "description": "namespaces, by name" + }, + "tag": { + "type": "string", + "maxLength": 240, + "title": "Tag", + "description": "an entity's name or id, as activities tag it", + "default": "" + }, + "from_day": { + "anyOf": [ + { + "type": "string", + "pattern": "^\\d{4}-\\d{2}-\\d{2}$" + }, + { + "type": "null" + } + ], + "title": "From Day", + "description": "from this day (YYYY-MM-DD, the viewer's own days)" + }, + "to_day": { + "anyOf": [ + { + "type": "string", + "pattern": "^\\d{4}-\\d{2}-\\d{2}$" + }, + { + "type": "null" + } + ], + "title": "To Day", + "description": "to this day, included" + }, + "automation": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Automation", + "description": "an automation's id: what it did or caused" + }, + "q": { + "type": "string", + "maxLength": 200, + "title": "Q", + "description": "words in the summary", + "default": "" + }, + "unreviewed": { + "type": "boolean", + "title": "Unreviewed", + "description": "only those you haven't marked reviewed", + "default": false + }, + "important": { + "type": "boolean", + "title": "Important", + "description": "only those you marked important", + "default": false + }, + "order": { + "type": "string", + "enum": [ + "latest", + "for_you" + ], + "title": "Order", + "default": "latest" + } + }, + "additionalProperties": false, + "type": "object", + "title": "TimelineViewState", + "description": "What the timeline shows: its filters and order, as the page's address has them (docs/timeline.md, Saved views).\nThe same filters as GET /activities, with dates as days." + }, + "TimelineViewUpdate": { + "properties": { + "name": { + "anyOf": [ + { + "type": "string", + "maxLength": 60, + "minLength": 1 + }, + { + "type": "null" + } + ], + "title": "Name" + }, + "state": { + "anyOf": [ + { + "$ref": "#/components/schemas/TimelineViewState" + }, + { + "type": "null" + } + ], + "description": "save what the timeline shows now into it" + } + }, + "additionalProperties": false, + "type": "object", + "title": "TimelineViewUpdate", + "description": "Only what you send changes." + }, "TokenLimits": { "properties": { "default_days": {