This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: store connection URIs in strata records, chunked D1 queries

- Lexicon: add connections field (array of AT URIs)
- getIslands: reconstruct island from stored connections in chunks of 50
- Backfill existing records with 341 connection URIs each
- Landing page loads summaries, frontend fetches full data via API

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>

author
nandi
co-author
Letta Code
date (May 14, 2026, 3:18 AM UTC) commit 2538fdfb parent 8c325252
+60 -6
+10 -1
lexicons/org/latha/strata/strata.json
··· 14 14 "source": { 15 15 "type": "ref", 16 16 "ref": "#sourceRef", 17 - "description": "The source record that triggered this analysis." 17 + "description": "The source record that triggered this analysis. For islands, this is the lexmin vertex." 18 + }, 19 + "connections": { 20 + "type": "array", 21 + "maxLength": 500, 22 + "items": { 23 + "type": "string", 24 + "format": "at-uri" 25 + }, 26 + "description": "AT URIs of the network.cosmik.connection records that form this island. The island's edges — the stigmergic trail itself." 18 27 }, 19 28 "analysis": { 20 29 "type": "ref",
+50 -5
src/worker.ts
··· 379 379 380 380 // Landing page — strata records feed 381 381 app.get("/", async (c) => { 382 + // Just load summaries for the landing page — client-side will fetch full data 382 383 let islandsJson = "[]"; 383 384 try { 384 385 await ensureContrailReady(db); 385 386 const rows = await db 386 - .prepare("SELECT uri, record FROM records_strata ORDER BY time_us DESC LIMIT 50") 387 + .prepare("SELECT uri, record FROM records_strata ORDER BY time_us DESC LIMIT 10") 387 388 .all<{ uri: string; record: string }>(); 388 389 389 390 const islands: any[] = []; ··· 432 433 const lexmin = rec.source?.uri; 433 434 if (!lexmin) continue; 434 435 435 - // Compute stable ID from lexmin 436 436 const lexminHash = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(lexmin)); 437 437 const id = Array.from(new Uint8Array(lexminHash)).map(b => b.toString(16).padStart(2, "0")).join("").slice(0, 16); 438 438 439 + // Reconstruct island from stored connections (chunked for D1) 440 + const connectionUris: string[] = rec.connections || []; 441 + let vertices: string[] = []; 442 + let edges: any[] = []; 443 + let vertexMeta: Record<string, any> = {}; 444 + 445 + if (connectionUris.length > 0) { 446 + const CHUNK_SIZE = 50; 447 + const vertexSet = new Set<string>(); 448 + 449 + for (let i = 0; i < connectionUris.length; i += CHUNK_SIZE) { 450 + const chunk = connectionUris.slice(i, i + CHUNK_SIZE); 451 + const placeholders = chunk.map(() => "?").join(","); 452 + const connRows = await db 453 + .prepare(`SELECT r.record, r.did, r.rkey, i.handle FROM records_connection r LEFT JOIN identities i ON r.did = i.did WHERE r.uri IN (${placeholders})`) 454 + .bind(...chunk) 455 + .all<{ record: string; did: string; rkey: string; handle: string | null }>(); 456 + 457 + for (const cr of connRows.results || []) { 458 + try { 459 + const val = JSON.parse(cr.record); 460 + vertexSet.add(val.source); 461 + vertexSet.add(val.target); 462 + edges.push({ 463 + uri: `at://${cr.did}/network.cosmik.connection/${cr.rkey}`, 464 + did: cr.did, rkey: cr.rkey, 465 + source: val.source, target: val.target, 466 + connectionType: val.connectionType || "relates", 467 + note: val.note || "", handle: cr.handle, 468 + }); 469 + } catch {} 470 + } 471 + } 472 + vertices = [...vertexSet].sort(); 473 + vertexMeta = Object.fromEntries(await resolveVertexMeta(db, vertices)); 474 + } 475 + 476 + const analysis = rec.analysis || {}; 439 477 islands.push({ 440 - id, 441 - lexmin, 442 - title: rec.analysis?.title || null, 478 + id, lexmin, vertices, edges, vertexMeta, 479 + title: analysis.title || null, 480 + strata: analysis.synthesis ? { 481 + prose: analysis.synthesis || "", title: analysis.title || "", 482 + themes: analysis.themes || [], 483 + relationships: (analysis.connections || []).map((conn: any) => conn.description || ""), 484 + tensions: analysis.tensions || [], 485 + open_questions: analysis.openQuestions || [], 486 + synthesis: analysis.synthesis || "", 487 + } : null, 443 488 recordUri: row.uri, 444 489 }); 445 490 } catch {}