SDK
SDK Reference
TypeScript SDK for llmtxt - compression, patching, versioning, lifecycle, consensus, and retrieval
llmtxt SDK Reference
The llmtxt npm package provides TypeScript primitives and an SDK for LLM agent content workflows.
npm install llmtxtSubpath Exports
| Import | Description |
|---|---|
llmtxt | Core primitives: compress, decompress, hash, patch, diff, sign |
llmtxt/sdk | Collaborative document SDK: lifecycle, versions, consensus, attribution, storage, retrieval |
llmtxt/disclosure | Progressive disclosure: overview, sections, search, line range |
llmtxt/similarity | Text similarity: n-gram and shingle matching |
llmtxt/graph | Knowledge graph: mentions, tags, directives extraction |
Core Primitives
Compression
compress(data)- Zlib-compress a UTF-8 stringdecompress(data)- Decompress zlib bytes back to string
Hashing and IDs
hashContent(data)- SHA-256 hex hashgenerateId()- 8-character base62 ID from UUID v4calculateTokens(text)- Estimate token count (4 chars per token)
Patching
createPatch(original, modified)- Create unified diffapplyPatch(original, patchText)- Apply unified diffreconstructVersion(base, patchesJson, target)- Rebuild version N from patch chain (single WASM call)squashPatches(base, patchesJson)- Compact N patches into one diff
Diff
computeDiff(oldText, newText)- Line-based diff with token impact statsdiffVersions(base, patchesJson, from, to)- Diff between arbitrary versionscomputeSectionsModified(old, new)- Detect which markdown sections changed
Signing
computeSignature(slug, agentId, conversationId, expiresAt, secret)- HMAC-SHA256 for signed URLsderiveSigningKey(apiKey)- Derive per-agent signing key
SDK Modules
Lifecycle (llmtxt/sdk)
DocumentStatetype: DRAFT, REVIEW, LOCKED, ARCHIVEDisValidTransition(from, to)- Check if state transition is allowedisEditable(state)- Check if document accepts modificationsisTerminal(state)- Check if state has no outgoing transitions
Versions (llmtxt/sdk)
reconstructVersion(base, patches, targetVersion?)- Rebuild any versionsquashPatches(base, patches)- Compact patch chaindiffVersions(base, patches, from, to)- Diff stats between versionscomputeReversePatch(before, after)- Create rollback patchvalidatePatchApplies(content, patchText)- Pre-flight conflict check
Consensus (llmtxt/sdk)
evaluateApprovals(reviews, policy, currentVersion)- Check review thresholdmarkStaleReviews(reviews, currentVersion)- Mark outdated reviews as STALEApprovalPolicysupports requiredCount, requireUnanimous, requiredPercentage (0-100), allowedReviewerIds, and timeoutMs
Attribution (llmtxt/sdk)
attributeVersion(version, diff)- Compute per-version attributionbuildContributorSummary(attributions)- Aggregate contributor stats
Retrieval (llmtxt/sdk)
planRetrieval(overview, budget, query?)- Token-budget-aware section selection
Progressive Disclosure (llmtxt/disclosure)
generateOverview(content)- Document structure with sections and token countsgetSection(content, name)- Extract named sectionsearchContent(content, query)- Search with context linesgetLineRange(content, start, end)- Extract line range with token statsqueryJsonPath(content, path)- JSONPath query for JSON documents
Similarity (llmtxt/similarity)
rankBySimilarity(sections, query, method?)- Rank sections by query relevance
Knowledge Graph (llmtxt/graph)
buildGraph(content)- Extract mentions, tags, directivestopTopics(graph, limit)- Most referenced topicstopAgents(graph, limit)- Most mentioned agents