Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| The docs service answers every artifacts call: docs can be made, listed, shared, moved, trashed, restored, searched, versioned and edited live in their own rooms, agents read, write and recall them only where their person and everyone in the conversation can, and folio events go out on the bus, while Docs' pages keep working as before. | 1 | /** |
| 2 | * What the docs service tells the rest of g1t about folios: `folio.*` | |
| 3 | * events on the bus (packages/contracts events.ts, `FolioEventData`). | |
| 4 | * Published with no `repoId`, so a folio never reaches a repository's | |
| 5 | * timeline or webhooks, and with a title only when the whole workspace | |
| 6 | * can read the folio. Never throws: an event that can't be told is | |
| 7 | * logged, and the change it is about still happened. | |
| 8 | */ | |
| 9 | import { eventsClient, type EventPayloads, type FolioEventData, type ServiceBinding } from "@g1t/contracts"; | |
| 10 | ||
| 11 | import { actorOf } from "../events.ts"; | |
| 12 | ||
| 13 | export type FolioEventType = "folio.created" | "folio.updated" | "folio.trashed" | "folio.restored" | "folio.shared" | "folio.stale"; | |
| 14 | ||
| 15 | export async function publishFolioEvent<T extends FolioEventType>(events: ServiceBinding | undefined, type: T, data: EventPayloads[T] & FolioEventData, actor: string | null): Promise<void> { | |
| 16 | if (!events) return; | |
| 17 | try { | |
| 18 | await eventsClient(events).publish([{ type, source: "docs", repoId: null, actor: actorOf(actor), data } as never]); | |
| 19 | } catch (error) { | |
| 20 | console.error("folios could not publish", type, String(error)); | |
| 21 | } | |
| 22 | } |