@gik-ai/kernel
v0.1.2
Published
The embeddable Generative Interaction Kernel: interprets a portable UI-intent document into a running, reactive interface.
Maintainers
Readme
@gik-ai/kernel
The embeddable Generative Interaction Kernel: it interprets a portable UI-intent document into a running, reactive interface, delegating everything domain- and framework-specific to pluggable providers. The kernel owns the invariants (grammar, validation, reduction) and is dependency-free.
npm install @gik-ai/kernelimport { Kernel, GIKClient, KernelTransportHost, InMemoryStateModel } from "@gik-ai/kernel";
// Own the runtime in process: one dispatch produces one revision.
const kernel = new Kernel(/* manifest, document */);When to use
- You want local runtime authority and deterministic execution in-process.
- You are connecting a remote renderer to an authoritative host over the GIK wire protocol
(
GIKClient+KernelTransportHost).
Package boundary
The kernel owns document validation, state revisions, deterministic reduction, effect declarations, snapshots, and compensation. Renderers, storage, transports, domain components, and effect execution are supplied by other packages or by the host application.
The TypeScript exports are the API authority. See the project documentation for architecture, protocol, and compatibility contracts.
Exported API
Runtime classes
Kernelis the main runtime class:- Constructor:
new Kernel(manifest: Enveloped<ExecutableVocabularyManifest>, document: Enveloped<ExecutableProgramDefinition>, opts?: KernelOptions) KernelOptionscan supply customexpression,predicateExpression,state,contexts,registry,orchestrator,sink,validate,admitProgramPatch, andexecuteGraphExtension.- Core methods:
init(),dispatch(event),syncExternal(),resolve(),whenIdle(),state(), andprogram(). - Additional public methods:
hasProjection(),start(),publish(),publishSync(),mutate(),resume(),execution(),applyProgramPatch(),subscribePatches(),subscribeProgress(),cancelInvocation(),checkpoint(),restore(),effectsSince(),compensate(),baseline(), andsnapshotPatch(). resolve()throwsProjectionUnavailableErrorwhen the current program has noroot.publishSync()requiresSyncJsonataExpressionProvider.
- Constructor:
GIKClientis the renderer-side replica over aTransportProvider:- Constructor:
new GIKClient(transport: TransportProvider, options?: GIKClientOptions) - Public methods:
start(),stop(),rebind(),getTree(),getRev(),get(path),subscribe(),subscribeProgress(), andemit(node, name, payload?, actorId?).
- Constructor:
KernelTransportHostbinds aKernelto one or moreTransportProviderconnections:- Constructor:
new KernelTransportHost(manifest: Enveloped<ProjectedVocabularyManifest>, document: Enveloped<ExecutableProgramDefinition>, kernel: Kernel, defaultTransport?: TransportProvider) - Public methods:
start(),attach(),detach(),stop(),dispatch(), andwhenIdle().
- Constructor:
TransportProvideris the transport contract used byGIKClientandKernelTransportHost:send(message)andsubscribe(listener).createInMemoryTransportPair()returns a connected[TransportProvider, TransportProvider]pair for in-memory transport wiring.
Program, vocabulary, and document contracts
ProgramDefinitionis the shared executable program shape. It can carryvocabulary,graph,handlers,machines, andderivations.ExecutableProgramDefinitionisProjectedProgramDefinition | HeadlessProgramDefinition.ProjectedProgramDefinitionaddsroot: DocNode.HeadlessProgramDefinitionhas noroot.
DocNodeis the authored projection node contract:capability,id, optionalprops, and optionaledges.ResolvedNodeis the resolved renderer-facing node contract:capability,id,props,visible,fallback, andchildren.ExecutableVocabularyManifestisProjectedVocabularyManifest | HeadlessVocabularyManifest.ProjectedVocabularyManifestcarriesversion, optionalexpression,namespaces,contexts,actions, acapabilitiesmap, and optionalexternals.CapabilityDescriptordescribes one capability's optionalpropsSchema,emits,slots, anddataProp.
Validation and provider contracts
validateProgramMessage(message)validates a program message and throwsValidationErroron failure.validateProgramDefinition(program, capabilities?)validates authored node props against capability descriptors and throwsValidationErroron failure.ValidationErrorextendsErrorand exposes the underlyingerrorsvalue.validateJsonValue(schema, value, label)validates a value against a supplied JSON schema.ExpressionProviderdefineseval(expr, data, bindings?).CapabilityRegistrydefineshas(type)andget(type).VocabularyRegistryimplementsCapabilityRegistryand also providesVocabularyRegistry.fromVocabulary(manifest).StateModeldefinessnapshot(),get(path), andapply(ops).InMemoryStateModelandCompositeStateModelimplement it.
Authoring and protocol helpers
- Action authoring helpers:
assign,assignFrom,emit,invoke,route,request, andguarded. - Program authoring helpers:
node,projectedProgram,authorProjectedProgram,program,authorProgram,generateVocabulary, andlintVocabularyReferences. - Protocol helpers:
envelope(type, payload)andunwrap(message).
License
MIT
