Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext buildIdeaRefUrl

From Leeroopedia
Knowledge Sources
Domains Cross_Referencing, Ideas
Last Updated 2026-10-24 12:00 GMT

Overview

Concrete tool for building and parsing idea reference URLs (`oc://idea/<threadId>`) used to cross-reference idea threads from documents.

Description

The buildIdeaRefUrl and parseIdeaRefUrl functions provide the URL building and parsing for the idea cross-referencing system. They generate `oc://idea/` URLs that encode thread IDs and optional entry IDs and dates.

The URL format is:

oc://idea/<threadId>?entry=<entryId>&date=<date>
  • threadId: Required, URL-encoded.
  • entryId: Optional, points to a specific entry within the thread.
  • date: Optional, the thread/entry date for display.

The parser handles both `URL`-parsed and raw string fallbacks, making it robust against different runtime environments.

Usage

  • Cross-referencing: Generate `oc://idea/` links to embed in documents.
  • Parsing: Extract thread ID, entry ID, and date from idea reference URLs.
  • Editor integration: Used by the Tiptap IdeaRefBlock to render idea references.

Code Reference

Source Location

  • Repository: OpenContext
  • File: src/ui/src/utils/ideaRef.js

Signature

/**
 * Build an idea reference URL
 * @param {{ threadId: string, entryId?: string, date?: string }} params
 * @returns {string} oc://idea/<threadId>?entry=<entryId>&date=<date>
 */
export function buildIdeaRefUrl({ threadId, entryId, date }) {
  const safeThreadId = encodeURIComponent(String(threadId || '').trim());
  const params = new URLSearchParams();
  if (entryId) params.set('entry', String(entryId));
  if (date) params.set('date', String(date));
  return `oc://idea/${safeThreadId}${params.toString() ? `?${params.toString()}` : ''}`;
}

/**
 * Parse an idea reference URL
 * @param {string} href - oc://idea/... URL
 * @returns {{ threadId: string, entryId: string, date: string } | null}
 */
export function parseIdeaRefUrl(href) { ... }

Import

import { buildIdeaRefUrl, parseIdeaRefUrl } from '../utils/ideaRef';

I/O Contract

Inputs (buildIdeaRefUrl)

Name Type Required Description
params.threadId string Yes Thread ID (URL-encoded)
params.entryId string No Optional entry ID
params.date string No Optional date

Outputs (buildIdeaRefUrl)

Name Type Description
returns string oc://idea/<threadId>?entry=<entryId>&date=<date>

Inputs (parseIdeaRefUrl)

Name Type Required Description
href string Yes oc://idea/... URL string

Outputs (parseIdeaRefUrl)

Name Type Description
returns null { threadId, entryId, date } or null if not an idea URL

Usage Examples

Build an Idea Reference URL

import { buildIdeaRefUrl } from '../utils/ideaRef';

// Thread only
const url1 = buildIdeaRefUrl({ threadId: 'abc-123' });
// => "oc://idea/abc-123"

// With entry and date
const url2 = buildIdeaRefUrl({
  threadId: 'abc-123',
  entryId: 'entry-456',
  date: '2025-12-11'
});
// => "oc://idea/abc-123?entry=entry-456&date=2025-12-11"

Parse an Idea Reference URL

import { parseIdeaRefUrl } from '../utils/ideaRef';

const parsed = parseIdeaRefUrl('oc://idea/abc-123?entry=entry-456&date=2025-12-11');
// => { threadId: 'abc-123', entryId: 'entry-456', date: '2025-12-11' }

// Non-idea URLs return null
const notIdea = parseIdeaRefUrl('oc://doc/abc-123');
// => null

Embed in Markdown

// Generate a markdown link for embedding in documents
const url = buildIdeaRefUrl({ threadId: thread.id, date: thread._date });
const markdownLink = `[${thread.title}](${url})`;
// => "[My Idea](oc://idea/abc-123?date=2025-12-11)"

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment