SDK Runtime (In-Process)
The SDK runtime executes a pok CommandConfig in process with an object-based context instead of a subprocess boundary.
Generated clients use this runtime through generateSdk() from @pokit/sdk-gen or pok-sdk generate, and you can also call it directly.
Import
import { createSdkRuntime } from '@pokit/core';
import type { CommandReturn, CommandContextInput, OptionalizeUndefined } from '@pokit/core';createSdkRuntime
const runtime = createSdkRuntime({
quiet: true, // default true (runner.exec won't stream output)
runPreChecks: true, // default true (runs command.pre checks)
validateOutput: true, // default true (validates command output if command.output exists)
});Options
reporterAdapter(optional): defaults tocreateRawReporterAdapter()prompter(optional): defaults tocreateRawPrompter({ strict: true })so SDK calls never promptquiet(optional, defaulttrue): controls runner output streaming forr.exec(...)runPreChecks(optional, defaulttrue): runscommand.prevalidateOutput(optional, defaulttrue): validates the value returned bycommand.run(...)againstcommand.outputwhen present
runtime.invoke
const result = await runtime.invoke(command, {
cwd: process.cwd(),
context: { /* object context */ },
args: ['--extra', 'positional', 'args'],
});Semantics (Non-Interactive)
- No prompting: missing required context values throw (same as CLI with
--no-tty) - Defaults are applied using the command’s Zod schemas (same defaulting behavior as CLI parsing)
prechecks run (unlessrunPreChecks: false)- If
command.outputexists andvalidateOutputis enabled, the returned value is validated before being returned
Typing Helpers
CommandContextInput<typeof command>: the input shape accepted by the command’s context schemas (usesz.input)OptionalizeUndefined<T>: makesfoo?: ...for fields that can beundefinedCommandReturn<typeof command>:voidfor commands withoutoutput, otherwise the typed structured output
Example:
type Ctx = OptionalizeUndefined<CommandContextInput<typeof command>>;
type Out = CommandReturn<typeof command>;Close
If you create a runtime, close it when you’re done (stops the reporter adapter):
runtime.close();