- Name
snapshot- Kind
- parameter
- Type
ThreadSnapshot- Requirement
- required
DocsAPI referenceUI machinesthread
thread machine
The public state machine contract for @grassroot/ui-machines/thread. The machine owns behaviour; the matching headless layer owns composition.
@grassroot/ui-machines/thread
Package
Service example
thread.tsts
import { createService } from "@grassroot/statechart";import { threadMachine } from "@grassroot/ui-machines/thread"; const service = createService(threadMachine, { input: {} });service.start();service.send({ type: "…" });service.stop();20 of 20
Exports
exportThreadState
valueexportThreadStatets
export declare const exportThreadState: (snapshot: ThreadSnapshot) => ThreadSerializedState;Name
Kind
Type
Requirement
snapshotparameter
ThreadSnapshotrequired
returnreturn value
ThreadSerializedStaten/a
- Name
return- Kind
- return value
- Type
ThreadSerializedState- Requirement
- n/a
ResolvedThreadCapabilitiests
type ResolvedThreadCapabilities = { readonly edit: boolean; readonly switchToBranch: boolean; readonly switchBranchDuringRun: boolean; readonly cancel: boolean; readonly queue: boolean;};Name
Kind
Type
Requirement
cancelproperty
booleanrequired
editproperty
booleanrequired
queueproperty
booleanrequired
switchBranchDuringRunproperty
booleanrequired
switchToBranchproperty
booleanrequired
- Name
cancel- Kind
- property
- Type
boolean- Requirement
- required
- Name
edit- Kind
- property
- Type
boolean- Requirement
- required
- Name
queue- Kind
- property
- Type
boolean- Requirement
- required
- Name
switchBranchDuringRun- Kind
- property
- Type
boolean- Requirement
- required
- Name
switchToBranch- Kind
- property
- Type
boolean- Requirement
- required
ThreadCapabilities
typeThreadCapabilitiests
type ThreadCapabilities = { readonly edit?: boolean; readonly switchToBranch?: boolean; readonly switchBranchDuringRun?: boolean; readonly cancel?: boolean; readonly queue?: boolean;};Name
Kind
Type
Requirement
cancelproperty
booleanoptional
editproperty
booleanoptional
queueproperty
booleanoptional
switchBranchDuringRunproperty
booleanoptional
switchToBranchproperty
booleanoptional
- Name
cancel- Kind
- property
- Type
boolean- Requirement
- optional
- Name
edit- Kind
- property
- Type
boolean- Requirement
- optional
- Name
queue- Kind
- property
- Type
boolean- Requirement
- optional
- Name
switchBranchDuringRun- Kind
- property
- Type
boolean- Requirement
- optional
- Name
switchToBranch- Kind
- property
- Type
boolean- Requirement
- optional
ThreadCommand
typeThreadCommandts
type ThreadCommand = CommandObject & ({ readonly type: "CANCEL"; readonly reason: "unanchored-steer";} | { readonly type: "DISPATCH"; readonly lane: ThreadQueueLane; readonly item: ThreadQueueItem;});ThreadContext
typeThreadContextts
type ThreadContext = { readonly threadId?: string; readonly headId?: string; readonly nodes: Readonly<Record<string, ThreadNode>>; readonly rootIds: readonly string[]; readonly queues: ThreadQueues; readonly editingMessageId?: string; readonly capabilities: ResolvedThreadCapabilities; readonly run: MachineState<RunValue, RunContext>;};Name
Kind
Type
Requirement
capabilitiesproperty
ResolvedThreadCapabilitiesrequired
editingMessageIdproperty
stringoptional
headIdproperty
stringoptional
nodesproperty
Readonly<Record<string, ThreadNode>>required
queuesproperty
ThreadQueuesrequired
rootIdsproperty
readonly string[]required
runproperty
MachineState<RunValue, RunContext>required
threadIdproperty
stringoptional
- Name
capabilities- Kind
- property
- Type
ResolvedThreadCapabilities- Requirement
- required
- Name
editingMessageId- Kind
- property
- Type
string- Requirement
- optional
- Name
headId- Kind
- property
- Type
string- Requirement
- optional
- Name
nodes- Kind
- property
- Type
Readonly<Record<string, ThreadNode>>- Requirement
- required
- Name
queues- Kind
- property
- Type
ThreadQueues- Requirement
- required
- Name
rootIds- Kind
- property
- Type
readonly string[]- Requirement
- required
- Name
run- Kind
- property
- Type
MachineState<RunValue, RunContext>- Requirement
- required
- Name
threadId- Kind
- property
- Type
string- Requirement
- optional
ThreadDiagnosticCodes
valueThreadDiagnosticCodests
export declare const ThreadDiagnosticCodes: readonly DiagnosticCatalogueEntry[];ThreadEvent
typeThreadEventts
type ThreadEvent = RunEvent | { readonly type: "RUN_EVENT"; readonly event: RunEvent;} | { readonly type: "APPEND"; readonly id: string; readonly parentId?: string;} | { readonly type: "APPEND_MESSAGE"; readonly id: string; readonly parentId?: string;} | { readonly type: "RELINK_MESSAGE"; readonly messageId: string; readonly parentId?: string;} | { readonly type: "DELETE_MESSAGE"; readonly messageId: string; readonly replacementId?: string | null;} | { readonly type: "RESET_HEAD"; readonly headId: string;} | { readonly type: "REWIND"; readonly headId: string;} | { readonly type: "SWITCH_HEAD"; readonly headId: string;} | { readonly type: "SWITCH_BRANCH"; readonly headId: string;} | { readonly type: "BEGIN_EDIT"; readonly messageId: string;} | { readonly type: "END_EDIT";} | { readonly type: "ENQUEUE"; readonly lane: ThreadQueueLane; readonly item: ThreadQueueItem;} | { readonly type: "QUEUE"; readonly lane: ThreadQueueLane; readonly item: ThreadQueueItem;} | { readonly type: "STEER"; readonly item: ThreadQueueItem;};ThreadInput
typeThreadInputts
type ThreadInput = { readonly threadId?: string; readonly runId?: string; readonly messages?: readonly ThreadMessageNodeInput[]; readonly headId?: string; readonly capabilities?: ThreadCapabilities; readonly state?: ThreadSerializedState;};Name
Kind
Type
Requirement
capabilitiesproperty
ThreadCapabilitiesoptional
headIdproperty
stringoptional
messagesproperty
readonly ThreadMessageNodeInput[]optional
runIdproperty
stringoptional
stateproperty
ThreadSerializedStateoptional
threadIdproperty
stringoptional
- Name
capabilities- Kind
- property
- Type
ThreadCapabilities- Requirement
- optional
- Name
headId- Kind
- property
- Type
string- Requirement
- optional
- Name
messages- Kind
- property
- Type
readonly ThreadMessageNodeInput[]- Requirement
- optional
- Name
runId- Kind
- property
- Type
string- Requirement
- optional
- Name
state- Kind
- property
- Type
ThreadSerializedState- Requirement
- optional
- Name
threadId- Kind
- property
- Type
string- Requirement
- optional
threadMachine
valuethreadMachinets
export declare const threadMachine: ThreadMachine;ThreadMachine
typeThreadMachinets
type ThreadMachine = Machine<ThreadInput, ThreadStateValue, ThreadContext, ThreadEvent, ThreadCommand>;ThreadMessageNodeInputts
type ThreadMessageNodeInput = { readonly id: string; readonly parentId?: string;};Name
Kind
Type
Requirement
idproperty
stringrequired
parentIdproperty
stringoptional
- Name
id- Kind
- property
- Type
string- Requirement
- required
- Name
parentId- Kind
- property
- Type
string- Requirement
- optional
ThreadNode
typeThreadNodets
type ThreadNode = { readonly id: string; readonly parentId?: string; readonly childIds: readonly string[];};Name
Kind
Type
Requirement
childIdsproperty
readonly string[]required
idproperty
stringrequired
parentIdproperty
stringoptional
- Name
childIds- Kind
- property
- Type
readonly string[]- Requirement
- required
- Name
id- Kind
- property
- Type
string- Requirement
- required
- Name
parentId- Kind
- property
- Type
string- Requirement
- optional
ThreadQueueItem
typeThreadQueueItemts
type ThreadQueueItem = { readonly id: string; readonly anchorId?: string;};Name
Kind
Type
Requirement
anchorIdproperty
stringoptional
idproperty
stringrequired
- Name
anchorId- Kind
- property
- Type
string- Requirement
- optional
- Name
id- Kind
- property
- Type
string- Requirement
- required
ThreadQueueLane
typeThreadQueueLanets
type ThreadQueueLane = "steer" | "queue";ThreadQueues
typeThreadQueuests
type ThreadQueues = { readonly steer: readonly ThreadQueueItem[]; readonly queue: readonly ThreadQueueItem[];};Name
Kind
Type
Requirement
queueproperty
readonly ThreadQueueItem[]required
steerproperty
readonly ThreadQueueItem[]required
- Name
queue- Kind
- property
- Type
readonly ThreadQueueItem[]- Requirement
- required
- Name
steer- Kind
- property
- Type
readonly ThreadQueueItem[]- Requirement
- required
threadReplaySequence
valuethreadReplaySequencets
export declare const threadReplaySequence: readonly ThreadEvent[];threadSelectors
valuethreadSelectorsts
export declare const threadSelectors: { isBusy: (snapshot: ThreadSnapshot) => boolean; runValue: (snapshot: ThreadSnapshot) => RunValue; editingMessageId: (snapshot: ThreadSnapshot) => string | undefined; branchChildren: (snapshot: ThreadSnapshot, id: string) => readonly string[]; queueLengths: (snapshot: ThreadSnapshot) => { steer: number; queue: number; }; capabilities: (snapshot: ThreadSnapshot) => ResolvedThreadCapabilities; messagesToHead: typeof messagesToHead; branches: (snapshot: ThreadSnapshot, id: string) => readonly string[];};Name
Kind
Type
Requirement
branchChildrenproperty
(snapshot: ThreadSnapshot, id: string) => readonly string[]required
branchesproperty
(snapshot: ThreadSnapshot, id: string) => readonly string[]required
capabilitiesproperty
(snapshot: ThreadSnapshot) => ResolvedThreadCapabilitiesrequired
editingMessageIdproperty
(snapshot: ThreadSnapshot) => string | undefinedrequired
isBusyproperty
(snapshot: ThreadSnapshot) => booleanrequired
messagesToHeadproperty
typeof messagesToHeadrequired
queueLengthsproperty
(snapshot: ThreadSnapshot) => {
steer: number;
queue: number;
}required
runValueproperty
(snapshot: ThreadSnapshot) => RunValuerequired
- Name
branchChildren- Kind
- property
- Type
(snapshot: ThreadSnapshot, id: string) => readonly string[]- Requirement
- required
- Name
branches- Kind
- property
- Type
(snapshot: ThreadSnapshot, id: string) => readonly string[]- Requirement
- required
- Name
capabilities- Kind
- property
- Type
(snapshot: ThreadSnapshot) => ResolvedThreadCapabilities- Requirement
- required
- Name
editingMessageId- Kind
- property
- Type
(snapshot: ThreadSnapshot) => string | undefined- Requirement
- required
- Name
isBusy- Kind
- property
- Type
(snapshot: ThreadSnapshot) => boolean- Requirement
- required
- Name
messagesToHead- Kind
- property
- Type
typeof messagesToHead- Requirement
- required
- Name
queueLengths- Kind
- property
- Type
(snapshot: ThreadSnapshot) => { steer: number; queue: number; }- Requirement
- required
- Name
runValue- Kind
- property
- Type
(snapshot: ThreadSnapshot) => RunValue- Requirement
- required
ThreadSerializedStatets
type ThreadSerializedState = { readonly value: ThreadStateValue; readonly context: ThreadContext;};Name
Kind
Type
Requirement
contextproperty
ThreadContextrequired
valueproperty
ThreadStateValuerequired
- Name
context- Kind
- property
- Type
ThreadContext- Requirement
- required
- Name
value- Kind
- property
- Type
ThreadStateValue- Requirement
- required
ThreadSnapshot
typeThreadSnapshotts
type ThreadSnapshot = Snapshot<ThreadStateValue, ThreadContext>;ThreadStateValue
typeThreadStateValuets
type ThreadStateValue = "ready" | "busy";