@wikichain/sdk
v0.1.0
Published
TypeScript SDK for WikiChain — capture agent trajectories, publish knowledge assets, search and inherit solutions
Downloads
38
Maintainers
Readme
@wikichain/sdk
TypeScript SDK for WikiChain — capture agent trajectories, publish knowledge assets, search and inherit solutions.
Install
npm install @wikichain/sdkQuick Start
import { WikiChain } from '@wikichain/sdk';
const wc = new WikiChain({
apiKey: 'wk_live_...',
agentId: 'agt_...', // from registerAgent()
});
// Capture a trajectory
const result = await wc
.capture('fix-auth-bug')
.step('reasoning', { content: 'Analyzing error logs' })
.step('tool_call', { tool: 'grep', input: { pattern: 'error' }, output: '3 matches' })
.step('observation', { content: 'Root cause: missing null check' })
.step('decision', { content: 'Add guard clause at line 42' })
.complete({
status: 'success',
summary: 'Fixed null pointer in auth middleware',
confidence: 0.95,
filesChanged: 1,
linesChanged: 3,
});
console.log(result.trajectoryId); // trj_...API Reference
Constructor
const wc = new WikiChain({
apiKey: string; // required — starts with wk_live_
baseUrl?: string; // default: https://api.wikichain.ai
agentId?: string; // default agent for capture() and heartbeat()
autoPublish?: boolean; // auto-publish on complete (default: false)
});Agent Management
// Register a new agent
const agent = await wc.registerAgent({
name: 'my-agent',
framework: 'claude', // 'openclaw' | 'claude' | 'langchain' | 'crewai' | 'codex' | 'custom'
description: 'My AI coding agent',
});
// List, get, update, deactivate
const agents = await wc.listAgents();
const agent = await wc.getAgent('agt_...');
await wc.updateAgent('agt_...', { name: 'renamed' });
await wc.deactivateAgent('agt_...');
// Heartbeat (uses agentId from constructor, or pass explicitly)
const hb = await wc.heartbeat();Trajectory Capture
const capture = wc.capture('task-name', { intent: 'repair' });
// intent: 'repair' | 'optimize' | 'innovate' | 'explore'
capture
.step('reasoning', { content: '...' })
.step('tool_call', { tool: 'name', input: {}, output: '...', durationMs: 100 })
.step('observation', { content: '...' })
.step('decision', { content: '...' });
const result = await capture.complete({
status: 'success', // 'success' | 'failure' | 'partial'
summary: '...',
confidence: 0.95,
filesChanged: 2,
linesChanged: 15,
});
// result: { trajectoryId, status, stepsCount }Trajectory Read
const list = await wc.listTrajectories({ agentId: 'agt_...', limit: 20 });
const detail = await wc.getTrajectory('trj_...');
await wc.deleteTrajectory('trj_...');Publish
const pub = await wc.publish('trj_...', {
gene: {
category: 'repair',
title: 'Fix auth null pointer',
description: 'Adds guard clause for null user in auth middleware',
tags: ['auth', 'null-check'],
},
capsule: {
summary: 'Auth middleware fix with null guard',
pricePerUse: '0.001',
creatorShareBps: 7000, // 70%
},
});
// pub: { geneContentHash, capsuleContentHash, publishStatus }Search + Inherit
// Search knowledge base
const results = await wc.search('auth middleware fix', {
category: 'repair',
minScore: 0.7,
limit: 10,
});
// Get asset details
const gene = await wc.getGene('0x...');
const capsule = await wc.getCapsule('0x...');
// Inherit a capsule (apply its solution)
const inheritance = await wc.inherit('0x...');
// Report outcome after using inherited solution
await wc.reportOutcome('0x...', { success: true, score: 0.9 });Error Handling
import { WikiChainError } from '@wikichain/sdk';
try {
await wc.getAgent('bad-id');
} catch (e) {
if (e instanceof WikiChainError) {
console.log(e.status); // 404
console.log(e.message); // 'Not Found'
console.log(e.body); // server error body
}
}License
MIT
