import type { ContrailConfig, PipelineQueryHandler } from "@atmo-dev/contrail"; // ── Pipeline queries: the Yoneda probes ───────────────────────────────── // // The Yoneda lemma: an object is determined by its relationships. // Hom(C(a, -), F) ≅ F(a) // // Two fundamental queries: // getIncoming -- all morphisms TO a resource (covariant probe: C(-, a)) // getOutgoing -- all morphisms FROM a resource (contravariant probe: C(a, -)) // // A resource "emerges" from the sum of its connections. const getIncoming: PipelineQueryHandler = async (db, params, config) => { const uri = params.get("uri"); if (!uri) throw new Error("uri is required"); const limit = Math.min(parseInt(params.get("limit") || "50"), 100); const cursor = params.get("cursor"); const types = params.get("types"); // comma-separated connection types const conditions = ["json_extract(record, '$.target') = ?"]; const sqlParams: (string | number)[] = [uri]; if (types) { const typeList = types.split(",").map((t) => t.trim()); const placeholders = typeList.map(() => "?").join(","); conditions.push(`json_extract(record, '$.connectionType') IN (${placeholders})`); sqlParams.push(...typeList); } if (cursor) { conditions.push("time_us < ?"); sqlParams.push(parseInt(cursor)); } const where = conditions.join(" AND "); return { joins: undefined, conditions: [where], params: sqlParams, }; }; const getOutgoing: PipelineQueryHandler = async (db, params, config) => { const uri = params.get("uri"); if (!uri) throw new Error("uri is required"); const limit = Math.min(parseInt(params.get("limit") || "50"), 100); const cursor = params.get("cursor"); const types = params.get("types"); const conditions = ["json_extract(record, '$.source') = ?"]; const sqlParams: (string | number)[] = [uri]; if (types) { const typeList = types.split(",").map((t) => t.trim()); const placeholders = typeList.map(() => "?").join(","); conditions.push(`json_extract(record, '$.connectionType') IN (${placeholders})`); sqlParams.push(...typeList); } if (cursor) { conditions.push("time_us < ?"); sqlParams.push(parseInt(cursor)); } const where = conditions.join(" AND "); return { joins: undefined, conditions: [where], params: sqlParams, }; }; export const config: ContrailConfig = { namespace: "org.latha.island", collections: { // ── Semble records (indexed from the network) ────────────────── card: { collection: "network.cosmik.card", queryable: { type: {}, "content.url": {}, }, searchable: ["content.url", "content.text", "content.metadata.title", "content.metadata.description"], references: { parentCard: { collection: "card", field: "parentCard.uri", }, }, }, collection: { collection: "network.cosmik.collection", queryable: { name: {}, accessType: {}, }, searchable: ["name", "description"], relations: { cards: { collection: "card", count: true, }, }, }, // ── Connection: the fundamental primitive (Yoneda) ────────────── // // Connections are morphisms in the knowledge graph. // Objects (cards, collections, URLs) emerge from their connections. // This is the Yoneda embedding: every object is determined by // the set of morphisms pointing at it and originating from it. connection: { collection: "network.cosmik.connection", queryable: { source: {}, target: {}, connectionType: {}, }, searchable: ["note"], pipelineQueries: { getIncoming, getOutgoing, }, }, // ── Follow: social graph for feed construction ───────────────── follow: { collection: "network.cosmik.follow", queryable: { subject: {}, }, discover: false, // only index follows from known users }, // ── Strata analysis records (generated by this appview) ──────── citation: { collection: "org.latha.island.citation", queryable: { url: {}, confidence: {}, domain: {}, }, searchable: ["title", "takeaway"], relations: { reasoning: { collection: "reasoning", groupBy: "method", count: true, }, }, }, entity: { collection: "org.latha.island.entity", queryable: { entityType: {}, name: {}, }, searchable: ["name", "description"], }, reasoning: { collection: "org.latha.island.reasoning", queryable: { method: {}, confidence: {}, }, searchable: ["question", "evidence"], references: { citation: { collection: "citation", field: "justifies", }, }, }, // ── Strata synthesis: the stigmergic signal ──────────────────── // // When a user runs Strata analysis on a Semble card, the output // is an org.latha.island record on their PDS. It's a pheromone // trail — others discover it, build on it, the network effect // compounds. Carry stays local-first; only summaries go into // the record unless explicitly published as companion records. strata: { collection: "org.latha.island", queryable: { "source.uri": {}, "source.collection": {}, updatedAt: { type: "range" }, }, searchable: ["analysis.synthesis", "analysis.themes"], references: { sourceCard: { collection: "card", field: "source.uri", }, }, }, }, profiles: ["app.bsky.actor.profile"], notify: true, };