Runtime API Reference

Find the public API for each task below. Refer to the exported TypeScript declarations for exact input and result types. There is no umbrella SDK or public factory for a complete V11 autonomous CharacterSession.

Package installation status

All current workspace packages are private: true, version 0.0.0, and commonly depend on each other through workspace:*. Use them from this repository workspace. The SDK is not published to npm.

Platform-neutral ordinary Runtime

Import createCharaWeaveRuntime from @charaweave/runtime. It creates characters, accepts touch and activity commands, provides snapshots and diagnostics, and disposes its resources. It does not load a Character package or provide the V11 autonomous WHAT pipeline by itself.

import { createCharaWeaveRuntime } from "@charaweave/runtime";

const runtime = createCharaWeaveRuntime();
const character = runtime.createCharacter({
  instanceId: "example:cat-instance",
  characterDefinitionId: "example.simple-cat:cat",
});

const touch = await runtime.touch({
  type: "character.touch",
  commandId: "example:touch:1",
  instanceId: character.instanceId,
  expectedRevision: character.revision,
});

console.log(touch.status, runtime.getSnapshot(character.instanceId));
runtime.dispose();

The ordinary Runtime uses the Stable command and snapshot types from @charaweave/contracts.

Package validation and Content projection

Import loadCharacterContentV11 and CharacterPackageReaderV1 from @charaweave/content:

const result = await loadCharacterContentV11({ reader, characterId });
if (!result.ok) {
  for (const issue of result.issues) console.error(issue);
} else {
  const character = result.character;
  // validated, projected Content; asset loading/rendering remains consumer work
}

The reader is provided by the Consumer and implements readText(path) and exists(path). Content V11 projects V11 repertoire and Presentation semantics. Older Content projections intentionally expose fewer fields.

Core session facade

createCoreSession from @charaweave/core accepts { character, targetSessionPolicy } and returns a CoreSession with start/reset/dispose, Presentation Behavior state, finite presentation override, and Recovery operations. Its source currently loads Content V10. It is a platform-neutral ordinary facade; it does not expose an arbitrary WHAT selection API.

Platform convenience composition

createConsumerSession from @charaweave/platform accepts { character, targetSessionPolicy }. It creates an ordinary Runtime, Autonomy Session, and effective WHAT/WHEN policy; start() requires an attached Browser environment. The current implementation loads Content V6. Use it only when the V6 projection is appropriate. createBrowserEnvironment is exported from @charaweave/platform/browser; it accepts the session plus { character, approachClearancePx, motionDurationMs }, and returns attachHost(...) and an owned Browser environment.

@charaweave/react-browser provides ConsumerSessionProvider and useConsumerHost for that Platform Browser helper. This integration uses Content V6, not the complete V11 repertoire.

Capability-level Public composition

For lower-level autonomy, the Public package set includes:

Concern Public package and key exports
Effective action policy @charaweave/action-policy: resolveCharacterActionSelectionPolicyV1
Effective scheduling policy @charaweave/scheduling-policy: resolveCharacterSchedulingPolicyV1
Session target history and attempt acceptance @charaweave/autonomy: createAutonomySessionV1
Effective selection and action account @charaweave/autonomy: createActionAccountStateV1, selection facades, opportunity types
Semantic Host surfaces @charaweave/host: createHostSurfaceRegistry, createHostSurfaceTargetSelector, createHostSurfaceActionExecutor
Browser geometry @charaweave/host-browser: createBrowserHostGeometryAdapter
Browser execution @charaweave/browser-runtime: effective coordinator, Runtime Loop, motion, placement and infrastructure factories
React Host binding @charaweave/react-host-browser: CharaHostProvider, useCharaSurface

The exact input/output unions are in the respective package src/index.ts and declarations. Prefer effective-policy Browser coordinator/loop facades for new composition. The complete current export ledger is here.

Standard Core and Browser facade (V10 projection)

For a DOM Consumer with ordinary Core lifecycle, pair @charaweave/core with @charaweave/browser. This is distinct from the older V6 Platform helper. The matching React binding is @charaweave/react.

Entry point Inputs Outputs / failure
createCoreSession character reader/id, explicit targetSessionPolicy Promise of CoreSession; rejects invalid content or policy.
core.start / reset none status accepted or disposed.
core.setPresentationBehaviorState normal / calm / alert accepted, unsupported-state or disposed.
core.beginPresentationOverride none accepted with generation, unavailable or disposed.
core.completePresentationOverride generation boolean; stale terminal is not accepted.
core.requestRecovery return-to-safe-anchor or stabilize-in-place accepted with generation, unavailable or disposed.
core.completeRecovery generation and arrived/unavailable/failed boolean.
core.dispose none Disposes owned Core session.
createBrowserSession core, character execution port, clearance and duration; optional placement and observation callbacks BrowserSession; throws on invalid configuration, disposed/unknown Core or duplicate Browser owner.
browser.start / suspend / resume none accepted, stale or disposed; start requires ACTIVE Core.
browser.attachHost live Element, semantic ID, role, capabilities, optional trusted activation handler detachable attachment.
browser.pointerDown / Move / Up / Cancel / lostPointerCapture pointerId, clientX/Y, optional primary/button/capture/release boolean observation; caller forwards actual pointer lifecycle.
browser.requestRecovery recovery strategy lifecycle result.
browser.dispose none Releases Browser resources, not caller-owned Core.

Core states: CREATED_READY → ACTIVE → DISPOSED (reset returns the underlying session to its reset state). Browser states: READY, RUNNING, SUSPENDED, DISPOSED. Start the Core before starting the Browser. Attach only after the required DOM exists. Suspend or dispose Browser before removing owned DOM; dispose Core last. Browser execution callbacks report generation, WHY, WHAT and semantic target; terminal status may be completed, failed or cancelled, with a distinct interaction-context-invalidated event. Use the actual execution result.

Ordinary Runtime method reference

Method Input Result
createCharacter instanceId, characterDefinitionId CharacterSnapshotV1
touch character.touch command, commandId, instanceId, expectedRevision Promise of TouchCharacterResultV1
startActivity StartCharacterActivityCommandV1 Promise of StartCharacterActivityResultV1
reconcileCharacter instanceId not-found, no-op or completed result
getSnapshot instanceId snapshot or undefined
subscribe listener unsubscribe function
diagnostics.getEvents / getEffects instanceId domain event / effect diagnostics
diagnostics.drainEffects none attempted, acknowledged, failed, deadLettered counts
dispose none releases Runtime composition

Use the current revision from the returned snapshot when issuing a subsequent command. Inspect the result discriminator before reacting to a rejected/stale command. Diagnostics describe observations and are not a state mutation interface.

Host registry, geometry, target and action services

For caller-owned low-level composition use the Public Host and Browser Host packages. The standard Browser facade and Platform Browser helper already own their services; do not register the same Element twice.

Surface Main operations Result semantics
createHostSurfaceRegistry() registerSurface(descriptor), getSurface(id), getSurfaceRegistration(id), getSurfaces(), subscribe(listener), dispose() registration handle / current snapshot; generation scopes a registration to its registry lifetime.
createHostSurfaceTargetSelector(registry) discover(query), selectFirst(query), resolve(target) candidates; selected or no-match; current, surface-not-found or registration-changed.
createHostSurfaceActionExecutor(registry) registerSurfaceActions(id, handlers), activateSurface(id), dispose() handle and async executed, surface-not-found, capability-not-declared, handler-not-registered or handler-failed.
createBrowserHostGeometryAdapter() bindSurface(id, element), measureSurface(id), subscribe(listener), dispose() unbind handle; measured viewport CSS-pixel bounds, unbound or detached.

The registry validates exact schemaVersion/id/role/capabilities fields; IDs and roles have a different lexical contract than package resource IDs. See Host Integration. Keep the returned target reference intact. The registration generation identifies stale targets.

Autonomy attempt lifecycle

createAutonomySessionV1({characterInstanceId, policy}) returns created/session or invalid-policy/reason. Its explicit target-session policy is documented in the Behavior and Personality Reference.

This is a lower-level Public Host-action/target-memory path, not the full V11 CharacterSession. Use the returned attempt and the matching action-account and selection APIs. Do not construct attempt tokens or completion results yourself. See the TypeScript declarations for exact result types.

Policy and capability references

See Behavior and Personality Reference for exact input domains, trait formulas, explicit target-session policy and a runnable resolver example. Content loaders use a reader plus an optional character ID, returning a typed ok/character or !ok/issues union. Reader infrastructure failures can reject; distinguish those from structured validation issues.

Studio and Playground share their CharacterSession browser autonomy, presence, rest/sleep and manipulation drivers through @charaweave/browser/workspace-composition. This subpath is for workspace applications, not external consumers. The @charaweave/browser-runtime root no longer exports those drivers.

Lifecycle and disposal

Each composition owns resources it creates. Stop/cancel active scheduling and execution before disposing the Browser composition; detach Host surfaces before disposing their registry/geometry/action services; dispose Character/Autonomy session and Runtime exactly once. Do not dispose shared services from a child component.

The examples use public packages only. Target discovery and rendering remain application responsibilities. For the actual boundary and schema projection caveats, read Consumer Integration Manual.