diff --git a/README.md b/README.md index a5eb642ca..590928585 100644 --- a/README.md +++ b/README.md @@ -148,8 +148,8 @@ listed under [In progress](#in-progress), and what comes next under [Planned](#p templates to start from, a search by their words, a download as Markdown, and Undo and Recently deleted instead of a confirm. Export an asset or a collection as an evidence PDF with everything Lens found about it, or the parts you pick. Publish a namespace's resources, episodes, timeline activities or text as a private RSS feed or a podcast - feed that any feed reader or podcast app follows, and let a routine fill it on a schedule with what's new, or make - an episode about the week's new resources. ([Podcasts](docs/podcasts.md), + feed that any feed reader or podcast app follows (Feeds, from the Podcasts page), and let a routine fill it on a schedule with + what's new, or make an episode about the week's new resources. ([Podcasts](docs/podcasts.md), [specs from transcripts](docs/notes.md#specs-from-transcripts), [notes](docs/notes.md), [evidence PDFs](docs/api.md#evidence-pdfs), [published feeds](docs/feeds.md); [checks](docs/requirements.md#learn-from-it)) diff --git a/changelog.d/feeds-page.md b/changelog.d/feeds-page.md new file mode 100644 index 000000000..a7f9e7d8c --- /dev/null +++ b/changelog.d/feeds-page.md @@ -0,0 +1,5 @@ +- **Feeds in the web app.** The Feeds page, opened from Podcasts and under Explore once there is a feed, lists your + published feeds; New feed asks for a title, kind and namespace (Enter makes it); a feed's page copies the address in + one click, gets a new one, edits what readers show, takes items out and deletes the feed with Undo instead of a + confirm. The publishing nodes are on the canvas, with the feed picked from a list ([In the web + app](docs/feeds.md#in-the-web-app)). diff --git a/docs/feeds.md b/docs/feeds.md index 72aeda12d..8710f8c17 100644 --- a/docs/feeds.md +++ b/docs/feeds.md @@ -1,7 +1,7 @@ # Published feeds (RSS and podcasts) -**Status: in progress.** Feeds, their private addresses, the API, the MCP tools and the workflow nodes that let a -routine fill a feed or make an episode on a schedule are built. The Feeds page in the web app comes next. +**Status: built.** Feeds, their private addresses, the API, the MCP tools, the workflow nodes that let a routine fill a +feed or make an episode on a schedule, and the Feeds page in the web app. A namespace can publish what's in it as a feed that any feed reader or podcast app follows: new resources, podcast episodes, things on the timeline, or text a person or an agent wrote. Each feed has a private address; add it to the @@ -48,6 +48,24 @@ again adds only what's new. A feed lists its newest items (50 by default, up to Feed readers poll; the feed answers `304 Not Modified` when nothing changed (its `ETag`), and notes when a reader last read it (`fetched_at`, at most once a minute), so the web app can show that a podcast app is subscribed. +## In the web app + +**Feeds** lists the feeds in the namespaces you can read: each one's kind, namespace, how many items it holds and when +an app last read it. Open it with **Feeds** at the top of the Podcasts page, or Jump to; once there's a feed, it's also +under Explore in the navigation (left out before that, so a phone's menu stays as short as it was). **New feed** asks +for a title (focused; Enter makes it), the kind and the namespace, which is the one picked in the top bar when you can +edit it; the feed opens on its page. + +A feed's page shows its address with a **Copy** button, when an app last read it, and **New address** (editors), which +stops the old one at once. Editors change what readers show (title, description, author, language, category, artwork, +how many items a reader sees, and whether a podcast is explicit) and save with Enter. The items are listed newest +first, each a link to what it's about; **Remove** takes one out at once with an Undo in the toast, which adds the same +thing again. **Delete** deletes the feed at once with an Undo, which makes it again with its settings and items, at a +new address (the old token is gone for good). What a feed listed stays in Lens either way. + +On the canvas, a graph workflow's palette has the publishing nodes under Data (Select assets, Select activities) and +Keep (Publish to feed, Podcast episode); a feed is picked from a list, and the canvas names it on the node. + ## From a routine A routine fills a feed on a schedule with a graph workflow ([Publishing from the graph](processing.md#publishing-from-the-graph)): @@ -76,4 +94,5 @@ Agents use the MCP tools `list_feeds` (each feed's address, or one feed with its Refine later: artwork Lens makes for a feed without an `image`; Atom and JSON Feed alongside RSS; chapters and transcripts in a podcast feed (`podcast:transcript`); an automation action that publishes to a feed when something -happens. +happens; a preview of the feed's XML on its page; Try on the canvas listing what Publish to feed would add, item by +item. diff --git a/docs/processing.md b/docs/processing.md index ab26f2861..75dbe3d83 100644 --- a/docs/processing.md +++ b/docs/processing.md @@ -840,8 +840,10 @@ schedule. Their nodes: *namespace* named, else the *feed*'s, else where an admin's episode goes; a source its readers couldn't read is left out. With a *feed*, the episode is added to it and listed once it's made. -A run's result counts what was `published` and the `episodes` made, and its log says what each node did. Try on the -canvas runs a graph workflow over the namespaces you pick and says what each node would do, without publishing. So +A run's result counts what was `published` and the `episodes` made, and its log says what each node did. On the +canvas the nodes are under Data and Keep in a graph workflow's palette, the feed is picked from a list, and the canvas +says what to fix before Publish (a feed to choose, a limit over the most). Try on the canvas runs a graph workflow over +the namespaces you pick and says what each node would do, without publishing. So Select assets → Podcast episode (feed *Weekly*, length 10) on a routine that runs every Monday makes an episode about the week's new resources and puts it in your podcast app; Select activities (kinds `asset.added`) → Publish to feed puts the timeline in your feed reader. diff --git a/docs/requirements.md b/docs/requirements.md index 6fa07c2e5..27ea963a9 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -178,6 +178,7 @@ request, to another check that proves the same thing; loosening a requirement or | Undo and Recently deleted instead of a confirm | [test_notebook.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_notebook.py) `test_recently_deleted`; [notes-delete.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/notes-delete.test.tsx) | | A namespace publishes a private RSS feed or a podcast feed (Apple Podcasts' tags, audio with byte ranges) of resources, episodes, timeline activities and text, holding only what its readers can already read; through the API and MCP | [test_feeds.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_feeds.py) `test_making_filling_and_reading_a_feed`, `test_a_podcast_feed_lists_what_has_audio`, `test_timeline_activities_in_a_feed`, `test_vaults_and_settings`, `test_agents_use_feeds` | | A routine fills a feed on a schedule, or makes a podcast episode about what's new: graph workflow nodes pick the resources or timeline activities since the last run, add them to a feed, or make an episode about them; Try says what they would do | [test_feed_nodes.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_feed_nodes.py) `test_a_routine_publishes_new_resources_to_a_feed`, `test_a_routine_publishes_the_timeline_and_text`, `test_a_routine_makes_an_episode_and_the_feed_lists_it_once_made`, `test_try_says_what_it_would_do_and_bad_settings_are_refused` | +| Feeds in the web app: a Feeds page, reached from the Podcasts page and under Explore once there is a feed; New feed with the title focused and Enter making it in the current namespace; a feed's page copies the address in one click, gets a new one, edits what readers show, and takes items out or deletes the feed with Undo instead of a confirm; the publishing nodes on the canvas, checked before Publish | [feeds-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/feeds-ui.test.tsx) `the Feeds page lists each feed with its kind, namespace, items and whether an app reads it`, `New feed opens on the title, defaults to the current namespace, and Enter makes it and opens its page`, `a feed's page copies the address, gets a new one, and takes an item out with Undo`, `deleting a feed is undone by making it again with its items, at a new address`, `editors change what readers show, and Enter in a field saves`; [workflow-flow.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/workflow-flow.test.ts) `a Select node into Publish to feed or Podcast episode is a whole graph workflow`, `says what to fix: a feed to choose, the limits, and a graph that publishes nothing`, `names the selection and the feed on the canvas`; [nav-groups.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/nav-groups.test.tsx) `feeds are under Explore, after Podcasts, for everyone`, `Feeds is in the nav only once there is a feed, so a phone's nav stays as short as it was` | | An asset or a collection exported as an evidence PDF, whole or the parts you pick | [test_evidence.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_evidence.py) `test_a_collection_as_one_evidence_pdf`, `test_everything_lens_found_goes_in`, `test_picking_the_parts`; [evidence-parts.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/evidence-parts.test.tsx) | ## Automate it diff --git a/nextjs-frontend/__tests__/feeds-ui.test.tsx b/nextjs-frontend/__tests__/feeds-ui.test.tsx new file mode 100644 index 000000000..443180a81 --- /dev/null +++ b/nextjs-frontend/__tests__/feeds-ui.test.tsx @@ -0,0 +1,249 @@ +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { fireEvent, render, screen, waitFor, within } from "@testing-library/react"; +import "@testing-library/jest-dom"; +import type { ReactNode } from "react"; + +import { Feeds } from "@/app/openapi-client"; +import type { Feed, FeedItem } from "@/app/openapi-client/types.gen"; +import { FeedPage } from "@/components/feeds/feed-page"; +import { FeedsScreen } from "@/components/feeds/feeds-screen"; +import { ToastProvider } from "@/components/ui/toast"; +import { TooltipProvider } from "@/components/ui/tooltip"; + +jest.mock("@/app/openapi-client", () => ({ + Feeds: { + listFeeds: jest.fn(), + createFeed: jest.fn(), + getFeed: jest.fn(), + updateFeed: jest.fn(), + deleteFeed: jest.fn(), + rotateFeedToken: jest.fn(), + listFeedItems: jest.fn(), + publishToFeed: jest.fn(), + removeFeedItem: jest.fn(), + }, +})); +jest.mock("next-auth/react", () => ({ useSession: () => ({ data: { accessToken: "t" } }) })); +const push = jest.fn(); +const replace = jest.fn(); +jest.mock("next/navigation", () => ({ useRouter: () => ({ push, replace }) })); +jest.mock("@/lib/hooks/session", () => ({ + useArchive: () => ({ + admin: true, + namespace: "home", + namespaces: [ + { id: 3, name: "home" }, + { id: 4, name: "work" }, + ], + can: () => true, + }), +})); + +const ok = (data: unknown) => Promise.resolve({ data, response: { ok: true, status: 200 } }); +const m = (f: unknown) => f as jest.Mock; +let writeText: jest.Mock; +beforeAll(() => { + // Radix's checkbox measures itself; jsdom has no ResizeObserver + global.ResizeObserver = class { + observe() {} + unobserve() {} + disconnect() {} + } as unknown as typeof ResizeObserver; +}); +beforeEach(() => { + jest.clearAllMocks(); + writeText = jest.fn(() => Promise.resolve()); + Object.assign(navigator, { clipboard: { writeText } }); +}); + +const WEEKLY: Feed = { + id: 7, + space: 3, + namespace: "home", + kind: "podcast", + title: "Weekly", + author: "Lens", + explicit: false, + max_items: 50, + url: "https://lens.local/api/v1/feeds/public/lfd_secret1", + path: "/api/v1/feeds/public/lfd_secret1", + page: "/feeds/7", + items: 2, + last_item_at: "2026-10-17T10:00:00+00:00", + fetched_at: null, + created_at: "2026-10-10T10:00:00+00:00", +}; +const NEWS: Feed = { + ...WEEKLY, + id: 8, + kind: "rss", + title: "What’s new", + items: 0, + fetched_at: "2026-10-17T12:00:00+00:00", +}; +const ITEMS: FeedItem[] = [ + { + id: 1, + feed: 7, + kind: "episode", + guid: "recording/31", + title: "Capsids and shipments", + summary: "Two hosts on the week’s papers.", + published_at: "2026-10-17T10:00:00+00:00", + recording: 31, + by: "routine:2", + }, + { + id: 2, + feed: 7, + kind: "text", + guid: "text/digest-41", + title: "Weekly digest", + summary: "2 new this week", + link: "https://example.org/digest/41", + published_at: "2026-10-16T10:00:00+00:00", + }, +]; + +function wrap(ui: ReactNode) { + const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } }); + return render( + + + {ui} + + , + ); +} + +test("the Feeds page lists each feed with its kind, namespace, items and whether an app reads it", async () => { + m(Feeds.listFeeds).mockReturnValue(ok([WEEKLY, NEWS])); + wrap(); + const weekly = await screen.findByRole("link", { name: /Weekly/ }); + expect(weekly).toHaveAttribute("href", "/feeds/7"); + expect(within(weekly).getByText("Podcast")).toBeInTheDocument(); + expect(within(weekly).getByText("home")).toBeInTheDocument(); + expect(within(weekly).getByText("2 items")).toBeInTheDocument(); + expect(within(weekly).getByText("not read by an app yet")).toBeInTheDocument(); + const news = screen.getByRole("link", { name: /What’s new/ }); + expect(within(news).getByText("RSS")).toBeInTheDocument(); + expect(within(news).getByText("Nothing in it yet")).toBeInTheDocument(); + expect(within(news).getByText(/^read/)).toBeInTheDocument(); + // the top bar's namespace narrows the list + expect(m(Feeds.listFeeds).mock.calls[0][0].query).toEqual({ namespace: "home" }); +}); + +test("New feed opens on the title, defaults to the current namespace, and Enter makes it and opens its page", async () => { + m(Feeds.listFeeds).mockReturnValue(ok([])); + m(Feeds.createFeed).mockReturnValue(ok({ ...NEWS, id: 9, title: "Inbox" })); + wrap(); + expect(await screen.findByText("No feeds yet")).toBeInTheDocument(); + fireEvent.click(screen.getAllByRole("button", { name: "New feed" })[0]); + const title = await screen.findByLabelText("Title"); + await waitFor(() => expect(title).toHaveFocus()); + expect(screen.getByLabelText("Namespace")).toHaveValue("home"); + expect(screen.getByLabelText("Kind")).toHaveValue("rss"); + fireEvent.change(title, { target: { value: "Inbox" } }); + fireEvent.keyDown(title, { key: "Enter" }); + await waitFor(() => expect(Feeds.createFeed).toHaveBeenCalledTimes(1)); + expect(m(Feeds.createFeed).mock.calls[0][0].body).toEqual({ title: "Inbox", kind: "rss", namespace: "home" }); + await waitFor(() => expect(push).toHaveBeenCalledWith("/feeds/9")); + expect(await screen.findByText("Feed made")).toBeInTheDocument(); +}); + +test("a feed's page copies the address, gets a new one, and takes an item out with Undo", async () => { + m(Feeds.getFeed).mockReturnValue(ok(WEEKLY)); + m(Feeds.listFeedItems).mockReturnValue(ok(ITEMS)); + const rotated = { ...WEEKLY, url: "https://lens.local/api/v1/feeds/public/lfd_secret2" }; + m(Feeds.rotateFeedToken).mockImplementation(() => { + m(Feeds.getFeed).mockReturnValue(ok(rotated)); + return ok(rotated); + }); + m(Feeds.removeFeedItem).mockReturnValue(ok({ ok: true })); + m(Feeds.publishToFeed).mockReturnValue(ok({ added: [1], already: 0, refused: [] })); + wrap(); + expect(await screen.findByRole("heading", { level: 1 })).toHaveTextContent("Weekly"); + expect(screen.getByText("Podcast feed")).toBeInTheDocument(); + expect(screen.getByText(WEEKLY.url)).toBeInTheDocument(); + expect(screen.getByText("No app has read it yet.", { exact: false })).toBeInTheDocument(); + + fireEvent.click(screen.getByRole("button", { name: "Copy the address" })); + await waitFor(() => expect(writeText).toHaveBeenCalledWith(WEEKLY.url)); + + fireEvent.click(screen.getByRole("button", { name: "New address" })); + expect(await screen.findByText("https://lens.local/api/v1/feeds/public/lfd_secret2")).toBeInTheDocument(); + expect(m(Feeds.rotateFeedToken).mock.calls[0][0].path).toEqual({ fid: 7 }); + expect(screen.getByText("New address", { selector: "div" })).toBeInTheDocument(); + + // the items: an episode made by a routine (a link into Lens) and a text item (an outside link) + expect(screen.getByRole("link", { name: "Capsids and shipments" })).toHaveAttribute("href", "/podcasts/31"); + expect(screen.getByText("by a routine")).toBeInTheDocument(); + expect(screen.getByRole("link", { name: /Weekly digest/ })).toHaveAttribute("href", "https://example.org/digest/41"); + + fireEvent.click(screen.getByRole("button", { name: "Remove Capsids and shipments" })); + await waitFor(() => expect(Feeds.removeFeedItem).toHaveBeenCalledTimes(1)); + expect(m(Feeds.removeFeedItem).mock.calls[0][0].path).toEqual({ fid: 7, iid: 1 }); + fireEvent.click(await screen.findByRole("button", { name: "Undo" })); + await waitFor(() => expect(Feeds.publishToFeed).toHaveBeenCalledTimes(1)); + expect(m(Feeds.publishToFeed).mock.calls[0][0]).toMatchObject({ path: { fid: 7 }, body: { recordings: [31] } }); +}); + +test("deleting a feed is undone by making it again with its items, at a new address", async () => { + m(Feeds.getFeed).mockReturnValue(ok(WEEKLY)); + m(Feeds.listFeedItems).mockReturnValue(ok(ITEMS)); + m(Feeds.deleteFeed).mockReturnValue(ok({ ok: true })); + m(Feeds.createFeed).mockReturnValue(ok({ ...WEEKLY, id: 12, items: 0 })); + m(Feeds.publishToFeed).mockReturnValue(ok({ added: [5, 6], already: 0, refused: [] })); + wrap(); + await screen.findByRole("link", { name: "Capsids and shipments" }); + fireEvent.click(screen.getByRole("button", { name: "Delete" })); + await waitFor(() => expect(Feeds.deleteFeed).toHaveBeenCalledTimes(1)); + expect(await screen.findByText("Deleted “Weekly”")).toBeInTheDocument(); + expect(replace).toHaveBeenCalledWith("/feeds"); + fireEvent.click(screen.getByRole("button", { name: "Undo" })); + await waitFor(() => expect(Feeds.publishToFeed).toHaveBeenCalledTimes(1)); + expect(m(Feeds.createFeed).mock.calls[0][0].body).toMatchObject({ + namespace: "home", + kind: "podcast", + title: "Weekly", + author: "Lens", + max_items: 50, + }); + expect(m(Feeds.publishToFeed).mock.calls[0][0]).toEqual({ + client: expect.anything(), + path: { fid: 12 }, + body: { + recordings: [31], + activities: [], + texts: [ + { + title: "Weekly digest", + summary: "2 new this week", + link: "https://example.org/digest/41", + guid: "digest-41", + }, + ], + }, + }); + await waitFor(() => expect(replace).toHaveBeenCalledWith("/feeds/12")); +}); + +test("editors change what readers show, and Enter in a field saves", async () => { + m(Feeds.getFeed).mockReturnValue(ok(NEWS)); + m(Feeds.listFeedItems).mockReturnValue(ok([])); + m(Feeds.updateFeed).mockReturnValue(ok({ ...NEWS, author: "Ada" })); + wrap(); + const author = await screen.findByLabelText(/^Author/); + expect(screen.getByRole("button", { name: "Save" })).toBeDisabled(); + fireEvent.change(author, { target: { value: "Ada" } }); + expect(screen.getByRole("button", { name: "Save" })).toBeEnabled(); + fireEvent.submit(author.closest("form")!); + await waitFor(() => expect(Feeds.updateFeed).toHaveBeenCalledTimes(1)); + expect(m(Feeds.updateFeed).mock.calls[0][0]).toMatchObject({ + path: { fid: 8 }, + body: { author: "Ada", title: "What’s new" }, + }); + expect(await screen.findByText("Saved")).toBeInTheDocument(); + expect(screen.queryByLabelText("Explicit content")).not.toBeInTheDocument(); + expect(screen.getByText("Nothing in it yet", { selector: "h2" })).toBeInTheDocument(); +}); diff --git a/nextjs-frontend/__tests__/nav-groups.test.tsx b/nextjs-frontend/__tests__/nav-groups.test.tsx index 473eeedb9..3694e61e7 100644 --- a/nextjs-frontend/__tests__/nav-groups.test.tsx +++ b/nextjs-frontend/__tests__/nav-groups.test.tsx @@ -40,6 +40,24 @@ test("the timeline is under Explore for everyone", () => { expect(isActive("/timeline", "/timeline")).toBe(true); }); +test("feeds are under Explore, after Podcasts, for everyone", () => { + for (const admin of [true, false]) { + const items = navFor(admin); + const feeds = items.findIndex((i) => i.href === "/feeds"); + expect(items[feeds]?.group).toBe("Explore"); + expect(items[feeds - 1]?.href).toBe("/podcasts"); + } + expect(isActive("/feeds/7", "/feeds")).toBe(true); +}); + +test("Feeds is in the nav only once there is a feed, so a phone's nav stays as short as it was", () => { + const { unmount } = nav(false); + expect(screen.queryByRole("link", { name: /^Feeds/ })).not.toBeInTheDocument(); + unmount(); + nav(false, { feeds: 1 }); + expect(screen.getByRole("link", { name: "Feeds 1" })).toHaveAttribute("href", "/feeds"); +}); + test("Approvals is in the nav only while something waits, and Automate keeps its name either way", () => { const { unmount } = nav(false); expect(screen.queryByRole("link", { name: /Approvals/ })).not.toBeInTheDocument(); diff --git a/nextjs-frontend/__tests__/workflow-flow.test.ts b/nextjs-frontend/__tests__/workflow-flow.test.ts index cb59f7d2f..27b176f9c 100644 --- a/nextjs-frontend/__tests__/workflow-flow.test.ts +++ b/nextjs-frontend/__tests__/workflow-flow.test.ts @@ -154,6 +154,79 @@ describe("classify", () => { }); }); +describe("publishing from the graph", () => { + const names = { + template: () => undefined, + field: () => undefined, + feed: (id: number) => (id === 3 ? "Weekly" : undefined), + }; + const wf = ( + select: Record, + publish: Record | null, + type = "publish_feed", + ): WfGraph => ({ + nodes: [ + { id: "in", type: "input", config: {} }, + { id: "sel", type: "select_assets", config: select }, + ...(publish ? [{ id: "pub", type, config: publish }] : []), + ], + edges: [{ source: "in", target: "sel" }, ...(publish ? [{ source: "sel", target: "pub" }] : [])], + }); + + it("a Select node into Publish to feed or Podcast episode is a whole graph workflow", () => { + expect(problems(wf(defaultConfig("select_assets"), { feed: 3 }), kind, "graph")).toEqual({}); + expect( + problems(wf(defaultConfig("select_assets"), defaultConfig("podcast_episode"), "podcast_episode"), kind, "graph"), + ).toEqual({}); + for (const t of ["select_assets", "select_activities", "publish_feed", "podcast_episode"]) { + expect(inScope(t, "graph")).toBe(true); + expect(inScope(t, "recording")).toBe(false); + } + expect(portsOf({ id: "p", type: "publish_feed", config: {} }).outputs).toEqual([]); + expect(portsOf({ id: "s", type: "select_activities", config: {} }).outputs).toEqual(["out"]); + expect(defaultConfig("select_activities")).toEqual({ since: "last_run", limit: 50 }); + }); + + it("says what to fix: a feed to choose, the limits, and a graph that publishes nothing", () => { + expect(problems(wf({}, {}), kind, "graph").pub).toBe("Choose a feed."); + expect(problems(wf({ limit: 900 }, { feed: 3 }), kind, "graph").sel).toBe("At most is 1 to 500 resources."); + expect(problems(wf({ since: "yesterday" }, { feed: 3 }), kind, "graph").sel).toMatch(/^Since is/); + expect(problems(wf({}, null), kind, "graph")[""]).toBe( + "Add an Apply changes, Publish to feed or Podcast episode node, or the workflow changes nothing.", + ); + expect(problems(wf({}, { min_sources: 5, max_sources: 3 }, "podcast_episode"), kind, "graph").pub).toBe( + "Fewest sources is 1 to the most.", + ); + expect(problems(wf({}, { length: 0 }, "podcast_episode"), kind, "graph").pub).toBe("Length is 1 to 180 minutes."); + expect(problems(wf({}, { feed: 3 }), kind, "recording").pub).toBe("This node is for graph workflows."); + }); + + it("names the selection and the feed on the canvas", () => { + expect(nodeSummary({ id: "s", type: "select_assets", config: defaultConfig("select_assets") }, names)).toBe( + "since the routine last ran · up to 50", + ); + expect( + nodeSummary( + { + id: "s", + type: "select_activities", + config: { since: "week", limit: 20, kinds: ["asset.added"], q: "invoice" }, + }, + names, + ), + ).toBe("the past week · up to 20 · asset.added · “invoice”"); + expect(nodeSummary({ id: "p", type: "publish_feed", config: {} }, names)).toBe("Choose a feed"); + expect(nodeSummary({ id: "p", type: "publish_feed", config: { feed: 3 } }, names)).toBe("to Weekly"); + expect(nodeSummary({ id: "p", type: "publish_feed", config: { feed: 9 } }, names)).toBe("to feed #9"); + expect( + nodeSummary( + { id: "e", type: "podcast_episode", config: { ...defaultConfig("podcast_episode"), feed: 3 } }, + names, + ), + ).toBe("about 10 minutes · Deep dive · to Weekly"); + }); +}); + describe("entity filter", () => { const names = { template: () => undefined, field: () => undefined }; const wf = (config: Record): WfGraph => ({ diff --git a/nextjs-frontend/app/(app)/feeds/[id]/page.tsx b/nextjs-frontend/app/(app)/feeds/[id]/page.tsx new file mode 100644 index 000000000..ed5cd17f2 --- /dev/null +++ b/nextjs-frontend/app/(app)/feeds/[id]/page.tsx @@ -0,0 +1,14 @@ +import type { Metadata } from "next"; +import { notFound } from "next/navigation"; + +import { FeedPage } from "@/components/feeds/feed-page"; + +export const metadata: Metadata = { title: "Feed" }; + +/** A feed: its private address, settings and items. */ +export default async function Page({ params }: { params: Promise<{ id: string }> }) { + const { id } = await params; + const fid = Number(id); + if (!Number.isInteger(fid) || fid <= 0) notFound(); + return ; +} diff --git a/nextjs-frontend/app/(app)/feeds/page.tsx b/nextjs-frontend/app/(app)/feeds/page.tsx new file mode 100644 index 000000000..38f4c5f5b --- /dev/null +++ b/nextjs-frontend/app/(app)/feeds/page.tsx @@ -0,0 +1,10 @@ +import type { Metadata } from "next"; + +import { FeedsScreen } from "@/components/feeds/feeds-screen"; + +export const metadata: Metadata = { title: "Feeds" }; + +/** Published RSS and podcast feeds (backend: app/domain/syndication.py). */ +export default function FeedsPage() { + return ; +} diff --git a/nextjs-frontend/components/app-shell/app-shell.tsx b/nextjs-frontend/components/app-shell/app-shell.tsx index fcbd0c4db..2462fee88 100644 --- a/nextjs-frontend/components/app-shell/app-shell.tsx +++ b/nextjs-frontend/components/app-shell/app-shell.tsx @@ -6,7 +6,7 @@ import Link from "next/link"; import { usePathname } from "next/navigation"; import { Suspense, useEffect, useState, type ReactNode } from "react"; -import { Speakers } from "@/app/openapi-client"; +import { Feeds, Speakers } from "@/app/openapi-client"; import { AccountMenu } from "@/components/app-shell/account-menu"; import { ActivityPill } from "@/components/app-shell/activity"; import { CommandPalette } from "@/components/app-shell/command-palette"; @@ -117,7 +117,17 @@ export function AppShell({ user, children }: { user: SessionUser; children: Reac staleTime: 60_000, }); const approvals = useApprovalCount(); - const counts = { recordings, reviews: reviews.data, approvals: approvals.data?.waiting || undefined }; + const feeds = useQuery({ + queryKey: ["feeds", "list", null], + queryFn: () => data(Feeds.listFeeds({ client })), + staleTime: 60_000, + }); + const counts = { + recordings, + reviews: reviews.data, + approvals: approvals.data?.waiting || undefined, + feeds: feeds.data?.length || undefined, + }; const canImport = can("editor", namespace); return ( diff --git a/nextjs-frontend/components/app-shell/nav-config.ts b/nextjs-frontend/components/app-shell/nav-config.ts index dbdb59739..598ea5f8e 100644 --- a/nextjs-frontend/components/app-shell/nav-config.ts +++ b/nextjs-frontend/components/app-shell/nav-config.ts @@ -12,6 +12,7 @@ import { NotebookPen, Podcast, RadioTower, + Rss, Search, Settings, Shapes, @@ -32,7 +33,7 @@ export type NavItem = { /** Only shown to people who aren't administrators (admins have it under another item). */ membersOnly?: boolean; /** A count shown next to the label (library size, speakers to review in Settings, approvals waiting). */ - countKey?: "recordings" | "reviews" | "approvals"; + countKey?: "recordings" | "reviews" | "approvals" | "feeds"; /** Shown only while its count is above zero, or while its page is open, so the nav of a Lens with nothing there * stays as short as it was (on a phone, every item more pushes the ones below off the screen). */ whileCounted?: boolean; @@ -61,6 +62,8 @@ export const NAV: NavItem[] = [ { label: "Topics", href: "/topics", icon: Tags, group: "Explore" }, { label: "Graph", href: "/graph", icon: Waypoints, group: "Explore" }, { label: "Podcasts", href: "/podcasts", icon: Podcast, group: "Explore" }, + // in the nav once there's a feed (Podcasts' Feeds button and Jump to lead there before that) + { label: "Feeds", href: "/feeds", icon: Rss, countKey: "feeds", whileCounted: true, group: "Explore" }, { label: "Reports", href: "/reports", icon: ChartNoAxesColumn, group: "Explore" }, // what waits for your pick: in the nav while anything does; the top bar's badge and Home's row lead there too { diff --git a/nextjs-frontend/components/app-shell/nav.tsx b/nextjs-frontend/components/app-shell/nav.tsx index d4dd83d70..842874a4c 100644 --- a/nextjs-frontend/components/app-shell/nav.tsx +++ b/nextjs-frontend/components/app-shell/nav.tsx @@ -26,7 +26,7 @@ export function Nav({ admin: boolean; collapsed: boolean; onToggle?: () => void; - counts: { recordings?: number; reviews?: number; approvals?: number }; + counts: { recordings?: number; reviews?: number; approvals?: number; feeds?: number }; onNavigate?: () => void; className?: string; top?: ReactNode; diff --git a/nextjs-frontend/components/feeds/create-feed-dialog.tsx b/nextjs-frontend/components/feeds/create-feed-dialog.tsx new file mode 100644 index 000000000..19d91ff1b --- /dev/null +++ b/nextjs-frontend/components/feeds/create-feed-dialog.tsx @@ -0,0 +1,133 @@ +"use client"; + +import { useQueryClient } from "@tanstack/react-query"; +import { useRouter } from "next/navigation"; +import { useEffect, useState } from "react"; + +import { Feeds } from "@/app/openapi-client"; +import { KINDS, type Kind } from "@/components/feeds/model"; +import { Button } from "@/components/ui/button"; +import { Dialog } from "@/components/ui/dialog"; +import { Field, Input, Select } from "@/components/ui/field"; +import { useToast } from "@/components/ui/toast"; +import { data, useApiClient } from "@/lib/api/browser"; +import { useArchive } from "@/lib/hooks/session"; + +/** Make a feed: a title (focused, Enter makes it), its kind and the namespace it publishes; then open its page, where + * its address is. The namespace is the one picked in the top bar when you can edit it, else the first you can. */ +export function CreateFeedDialog({ + open, + onOpenChange, + kind: startKind = "rss", +}: { + open: boolean; + onOpenChange: (open: boolean) => void; + kind?: Kind; +}) { + const client = useApiClient(); + const qc = useQueryClient(); + const toast = useToast(); + const router = useRouter(); + const { namespaces, namespace, can } = useArchive(); + const editable = namespaces.filter((n) => can("editor", n.name)); + const [title, setTitle] = useState(""); + const [kind, setKind] = useState(startKind); + const [ns, setNs] = useState(""); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(null); + const chosen = ns || (namespace && editable.some((n) => n.name === namespace) ? namespace : editable[0]?.name) || ""; + + useEffect(() => { + if (open) { + setError(null); + setKind(startKind); + } + }, [open, startKind]); + + const make = async () => { + if (!title.trim() || !chosen) return; + setBusy(true); + setError(null); + try { + const feed = await data(Feeds.createFeed({ client, body: { title: title.trim(), kind, namespace: chosen } })); + void qc.invalidateQueries({ queryKey: ["feeds"] }); + onOpenChange(false); + setTitle(""); + toast({ + title: kind === "podcast" ? "Podcast feed made" : "Feed made", + body: "Copy its address into your app. It’s private: share it like a password.", + tone: "green", + }); + router.push(`/feeds/${feed.id}`); + } catch (e) { + setError(e instanceof Error ? e.message : "Couldn’t make the feed."); + } finally { + setBusy(false); + } + }; + + const picked = KINDS.find((k) => k.value === kind); + return ( + + + + + } + > + + {(f) => ( + setTitle(e.target.value)} + /> + )} + +
+ + {(f) => ( + setNs(e.target.value)} + options={editable.map((n) => n.name)} + /> + )} + +
+ {error && ( +

+ {error} +

+ )} +
+ ); +} diff --git a/nextjs-frontend/components/feeds/feed-page.tsx b/nextjs-frontend/components/feeds/feed-page.tsx new file mode 100644 index 000000000..98cbd95b1 --- /dev/null +++ b/nextjs-frontend/components/feeds/feed-page.tsx @@ -0,0 +1,462 @@ +"use client"; + +import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import { ExternalLink, Podcast as PodcastIcon, Rss, Trash2 } from "lucide-react"; +import Link from "next/link"; +import { useRouter } from "next/navigation"; +import { useEffect, useState, type FormEvent } from "react"; + +import { Feeds } from "@/app/openapi-client"; +import type { Feed, FeedItem, FeedSettings } from "@/app/openapi-client/types.gen"; +import { ITEM_KINDS, itemHref, itemsText, kindLabel, republish } from "@/components/feeds/model"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { Checkbox, Field, Input, Select, Textarea } from "@/components/ui/field"; +import { Panel } from "@/components/ui/panel"; +import { CodeBlock, DateTime, EmptyState, PageHeader, SkeletonRows } from "@/components/ui/states"; +import { useToast } from "@/components/ui/toast"; +import { ApiError, data, useApiClient } from "@/lib/api/browser"; +import { useArchive } from "@/lib/hooks/session"; + +const SETTINGS: (keyof FeedSettings)[] = [ + "title", + "description", + "author", + "language", + "category", + "explicit", + "image", + "max_items", +]; + +/** A feed's page: its private address (copy it into a reader, or get a new one), its settings, and what it lists, each + * item with Remove. Deleting the feed can be undone from the toast; it comes back with a new address. */ +export function FeedPage({ id }: { id: number }) { + const client = useApiClient(); + const qc = useQueryClient(); + const toast = useToast(); + const router = useRouter(); + const { namespaces, can, admin } = useArchive(); + const q = useQuery({ queryKey: ["feeds", id], queryFn: () => data(Feeds.getFeed({ client, path: { fid: id } })) }); + const items = useQuery({ + queryKey: ["feeds", id, "items"], + queryFn: () => data(Feeds.listFeedItems({ client, path: { fid: id }, query: { limit: 200 } })), + enabled: q.isSuccess, + }); + const feed = q.data; + const ns = feed?.namespace ?? namespaces.find((n) => n.id === feed?.space)?.name; + const editor = can("editor", ns); + const refresh = () => { + void qc.invalidateQueries({ queryKey: ["feeds"] }); + }; + + const rotate = useMutation({ + mutationFn: () => data(Feeds.rotateFeedToken({ client, path: { fid: id } })), + onSuccess: (f) => { + qc.setQueryData(["feeds", id], f); + void qc.invalidateQueries({ queryKey: ["feeds", "list"] }); + toast({ title: "New address", body: "The old one stopped working. Copy this one into your app.", tone: "green" }); + }, + onError: (e: Error) => toast({ title: "Couldn’t make a new address", body: e.message, tone: "red" }), + }); + + const put = useMutation({ + mutationFn: (it: FeedItem) => + data(Feeds.publishToFeed({ client, path: { fid: id }, body: republish(it) })).then((r) => ({ it, r })), + onSuccess: ({ r }) => { + refresh(); + if (r.refused.length) toast({ title: "Couldn’t put it back", body: r.refused[0].why, tone: "red" }); + }, + onError: (e: Error) => toast({ title: "Couldn’t put it back", body: e.message, tone: "red" }), + }); + // Taking an item out is done at once with an Undo, which adds the same thing again under the same guid. + const remove = useMutation({ + mutationFn: (it: FeedItem) => data(Feeds.removeFeedItem({ client, path: { fid: id, iid: it.id } })).then(() => it), + onSuccess: (it) => { + refresh(); + toast({ + title: `Took “${it.title || ITEM_KINDS[it.kind] || "the item"}” out of the feed`, + body: "Readers stop seeing it when they next check.", + tone: "green", + action: { label: "Undo", onClick: () => put.mutate(it) }, + }); + }, + onError: (e: Error) => toast({ title: "Couldn’t take it out", body: e.message, tone: "red" }), + }); + + // Deleting is undone by making the feed again with its settings and items; its address is new, since the old token + // is gone for good. + const restore = useMutation({ + mutationFn: async ({ f, list }: { f: Feed; list: FeedItem[] }) => { + const made = await data( + Feeds.createFeed({ + client, + body: { + namespace: f.namespace ?? ns ?? "", + kind: f.kind, + title: f.title, + description: f.description, + author: f.author, + language: f.language, + category: f.category, + explicit: f.explicit, + image: f.image, + max_items: f.max_items, + }, + }), + ); + const body = { + recordings: list.flatMap((it) => republish(it).recordings ?? []), + activities: list.flatMap((it) => republish(it).activities ?? []), + texts: list.flatMap((it) => republish(it).texts ?? []), + }; + if (body.recordings.length || body.activities.length || body.texts.length) + await data(Feeds.publishToFeed({ client, path: { fid: made.id }, body })); + return made; + }, + onSuccess: (made) => { + refresh(); + toast({ title: "Feed is back", body: "With a new address: copy it into your app again.", tone: "green" }); + router.replace(`/feeds/${made.id}`); + }, + onError: (e: Error) => toast({ title: "Couldn’t bring the feed back", body: e.message, tone: "red" }), + }); + const del = useMutation({ + mutationFn: () => + data(Feeds.deleteFeed({ client, path: { fid: id } })).then(() => ({ f: feed!, list: items.data ?? [] })), + onSuccess: (kept) => { + refresh(); + toast({ + title: `Deleted “${kept.f.title}”`, + body: "Its address stopped working. What it listed is still in Lens.", + tone: "green", + action: { label: "Undo", onClick: () => restore.mutate(kept) }, + }); + router.replace("/feeds"); + }, + onError: (e: Error) => toast({ title: "Couldn’t delete it", body: e.message, tone: "red" }), + }); + + if (q.isPending) return ; + if (q.isError || !feed) { + const missing = q.error instanceof ApiError && (q.error.status === 404 || q.error.status === 403); + return ( + + All feeds + + } + > + {missing ? "It was deleted, or it’s in a namespace you can’t read." : (q.error as Error).message} + + ); + } + + return ( +
+ + {feed.kind === "podcast" ? ( + + ) : ( + + )} + {feed.title} + + } + meta={ + + {kindLabel(feed.kind)} feed + {ns && {ns}} + {itemsText(feed.items)} + + } + actions={ + editor && ( + + ) + } + /> + + rotate.mutate()}> + New address + + ) + } + bodyClassName="flex flex-col gap-2 px-4 pb-4" + > + +

+ {feed.fetched_at ? ( + <> + An app last read it . + + ) : ( + "No app has read it yet." + )}{" "} + {feed.kind === "podcast" + ? "In a podcast app, choose to follow a show by its address (in Apple Podcasts: Library, then Follow a Show by URL)." + : "Feed readers take the address as a new subscription."}{" "} + A new address stops the old one at once. +

+
+ + {editor && qc.setQueryData(["feeds", id], f)} />} + + + {items.isPending ? ( + + ) : items.isError ? ( + + {(items.error as Error).message} + + ) : !items.data.length ? ( + + Routines + + ) + } + > + A routine fills it on a schedule with the Publish to feed node, or makes a Podcast episode about what’s new. + Agents add to it through the API and MCP. + + ) : ( +
    + {items.data.map((it) => { + const href = itemHref(it); + const title = it.title || ITEM_KINDS[it.kind] || "Untitled"; + return ( +
  • + {ITEM_KINDS[it.kind] ?? it.kind} + + {href ? ( + href.startsWith("/") ? ( + + {title} + + ) : ( + + {title} + + + ) + ) : ( + {title} + )} + {it.summary && {it.summary}} + + {it.by?.startsWith("routine:") && by a routine} + + {editor && ( + + )} +
  • + ); + })} +
+ )} +
+
+ ); +} + +/** The feed's settings as readers see them, saved together (Enter in a field saves). */ +function SettingsPanel({ feed, onSaved }: { feed: Feed; onSaved: (f: Feed) => void }) { + const client = useApiClient(); + const toast = useToast(); + const from = (f: Feed): FeedSettings => ({ + title: f.title, + description: f.description ?? "", + author: f.author ?? "", + language: f.language ?? "", + category: f.category ?? "", + explicit: Boolean(f.explicit), + image: f.image ?? "", + max_items: f.max_items, + }); + const [v, setV] = useState(() => from(feed)); + useEffect(() => setV(from(feed)), [feed]); + const dirty = SETTINGS.some((k) => (v[k] ?? "") !== (from(feed)[k] ?? "")); + const save = useMutation({ + mutationFn: () => + data( + Feeds.updateFeed({ + client, + path: { fid: feed.id }, + body: { + title: String(v.title ?? "").trim() || feed.title, + description: String(v.description ?? "").trim() || null, + author: String(v.author ?? "").trim() || null, + language: String(v.language ?? "").trim() || null, + category: String(v.category ?? "").trim() || null, + explicit: Boolean(v.explicit), + image: String(v.image ?? "").trim() || null, + max_items: v.max_items ?? feed.max_items, + }, + }), + ), + onSuccess: (f) => { + onSaved(f); + toast({ title: "Saved", body: "Readers see the change when they next check.", tone: "green" }); + }, + onError: (e: Error) => toast({ title: "Couldn’t save", body: e.message, tone: "red" }), + }); + const submit = (e: FormEvent) => { + e.preventDefault(); + if (dirty && !save.isPending) save.mutate(); + }; + const set = (patch: Partial) => setV((x) => ({ ...x, ...patch })); + const podcast = feed.kind === "podcast"; + return ( + +
+
+ + {(f) => ( + set({ title: e.target.value })} + /> + )} + + + {(f) => ( + set({ author: e.target.value })} + /> + )} + +
+ + {(f) => ( +