KB LabsDocs

SDK API Reference

Last updated April 7, 2026


Every @kb-labs/sdk export — navigational index to the detailed SDK docs.

@kb-labs/sdk is the single import point for plugin authors. This page is a navigational index — each export group links to the detailed docs page that covers it in full.

For the full overview of what the SDK is and how it's structured, start with SDK → Overview.

Handler definitions

One helper per host type. Import from @kb-labs/sdk:

ExportHostDocs
defineCommandCLI, WorkflowSDK → Commands
defineRouteRESTSDK → Routes
defineActionREST (higher-level)SDK → Routes
defineWebhookWebhook
defineWebSocketWebSocket

Type guards for runtime host checks: isCLIHost, isRESTHost, isWorkflowHost, isWebhookHost, isWSHost.

Runtime hooks

All hooks read from the global platform singleton. Import from @kb-labs/sdk:

HookReturnsAlways present?Docs
usePlatform()PlatformSDK → Hooks
useLogger()ILoggerSDK → Hooks
useLLM()ILLM | undefinedSDK → Hooks
useCache()ICache | undefinedSDK → Hooks
useStorage()IStorage | undefinedSDK → Hooks
useVectorStore()IVectorStore | undefinedSDK → Hooks
useEmbeddings()IEmbeddings | undefinedSDK → Hooks
useAnalytics()IAnalytics | undefinedSDK → Hooks
useConfig<T>(key?)Promise<T | undefined>SDK → Hooks

useLogger always returns a logger — the platform provides a no-op fallback if no logger adapter is configured. All other hooks return undefined when the adapter isn't configured; always check before use:

TypeScript
const cache = useCache();
if (cache) {
  const hit = await cache.get<Result>(key);
}

Availability guards: isPlatformConfigured, isLLMAvailable, isCacheAvailable, isVectorStoreAvailable, isEmbeddingsAvailable.

Manifest helpers

TypeScript
import {
  defineManifest,       // typed ManifestV3 builder
  defineCommandFlags,   // typed flag schemas for cli.commands[i].flags
  defineFlags,          // general-purpose typed flag schema
  generateExamples,
} from '@kb-labs/sdk';

defineCommandFlags is the most commonly used — it lets you declare flags once and get both CLI parsing and type inference. See Plugins → Manifest Reference for the full manifest schema.

Permission primitives

TypeScript
import {
  combinePermissions,   // chainable builder
  combinePresets,       // convenience: combinePresets(a, b, c)
  minimalPreset,
  gitWorkflowPreset,
  npmPublishPreset,
  fullEnvPreset,
  kbPlatformPreset,
  llmAccessPreset,
  vectorStorePreset,
  ciEnvironmentPreset,
} from '@kb-labs/sdk';

See Plugins → Permissions for the full permission model.

Key types

TypeScript
import type {
  // Context
  PluginContextV3,
  HostContext,
  HostType,
  PlatformServices,
  // Adapters
  ILLM, ICache, IStorage, ILogger, IAnalytics, IEmbeddings, IVectorStore,
  // LLM
  LLMTier,           // 'small' | 'medium' | 'large'
  LLMOptions,
  LLMResponse,
  LLMMessage,
  LLMTool,
  // Manifest
  ManifestV3,
  PermissionSpec,
  // Results
  CommandResult,
  // UI data contracts
  TableData, ListData, MetricData, SelectData,
  // WebSocket
  WSMessage, WSSender,
  // Shell
  ShellAPI, ExecResult,
} from '@kb-labs/sdk';

See SDK → Handler Context for the full PluginContextV3 shape.

Utilities

TypeScript
import {
  // UI
  useLoader,              // spinner for CLI output
  displayArtifacts,
  displayArtifactsCompact,
  displaySingleArtifact,
 
  // Errors
  defineError,
  PluginError,
  commonErrors,
 
  // Environment
  defineEnv,
  parseEnvFromRuntime,
 
  // Tools (for LLM function-calling)
  createTool,
 
  // Repo introspection
  findRepoRoot,
  discoverSubRepoPaths,
} from '@kb-labs/sdk';

LLM tiers

The SDK exposes LLM access via useLLM(). The LLMTier controls which model class to use:

TierUse for
'small'Fast, cheap operations — classification, extraction, yes/no
'medium'Default — code analysis, generation, reasoning
'large'Complex multi-step reasoning, architecture analysis

See SDK → LLM Tiers for guidance on when to use each.

Testing

TypeScript
import { createTestContext } from '@kb-labs/sdk';
// Full mock builders:
import { /* ... */ } from '@kb-labs/sdk/testing';

See SDK → Testing.

Detailed SDK docs

PageCovers
OverviewWhat the SDK exports and when to import what
QuickstartSmallest possible plugin, end-to-end
CommandsdefineCommand, flags, handler lifecycle
RoutesdefineRoute, input/output schemas, Zod integration
HooksEvery hook — full API of each service
Handler ContextEverything in ctx
LLM TiersWhen to use small, medium, large
TestingcreateTestContext and mock builders
MigrationBreaking changes and upgrade paths
SDK API Reference — KB Labs Docs