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

20 exports
View source packages/ui-machines/src/thread/index.ts

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();

Exports

DeclarationView source
exportThreadStatets
export declare const exportThreadState: (snapshot: ThreadSnapshot) => ThreadSerializedState;
Name
Kind
Type
Requirement
snapshot
parameter
ThreadSnapshot
required
return
return value
ThreadSerializedState
n/a
Name
snapshot
Kind
parameter
Type
ThreadSnapshot
Requirement
required
Name
return
Kind
return value
Type
ThreadSerializedState
Requirement
n/a
DeclarationView source
ResolvedThreadCapabilitiests
type ResolvedThreadCapabilities = {
readonly edit: boolean;
readonly switchToBranch: boolean;
readonly switchBranchDuringRun: boolean;
readonly cancel: boolean;
readonly queue: boolean;
};
Name
Kind
Type
Requirement
cancel
property
boolean
required
edit
property
boolean
required
queue
property
boolean
required
switchBranchDuringRun
property
boolean
required
switchToBranch
property
boolean
required
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
DeclarationView source
ThreadCapabilitiests
type ThreadCapabilities = {
readonly edit?: boolean;
readonly switchToBranch?: boolean;
readonly switchBranchDuringRun?: boolean;
readonly cancel?: boolean;
readonly queue?: boolean;
};
Name
Kind
Type
Requirement
cancel
property
boolean
optional
edit
property
boolean
optional
queue
property
boolean
optional
switchBranchDuringRun
property
boolean
optional
switchToBranch
property
boolean
optional
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
DeclarationView source
ThreadCommandts
type ThreadCommand = CommandObject & ({
readonly type: "CANCEL";
readonly reason: "unanchored-steer";
} | {
readonly type: "DISPATCH";
readonly lane: ThreadQueueLane;
readonly item: ThreadQueueItem;
});
DeclarationView source
ThreadContextts
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
capabilities
property
ResolvedThreadCapabilities
required
editingMessageId
property
string
optional
headId
property
string
optional
nodes
property
Readonly<Record<string, ThreadNode>>
required
queues
property
ThreadQueues
required
rootIds
property
readonly string[]
required
run
property
MachineState<RunValue, RunContext>
required
threadId
property
string
optional
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
DeclarationView source
ThreadDiagnosticCodests
export declare const ThreadDiagnosticCodes: readonly DiagnosticCatalogueEntry[];
DeclarationView source
ThreadEventts
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;
};
DeclarationView source
ThreadInputts
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
capabilities
property
ThreadCapabilities
optional
headId
property
string
optional
messages
property
readonly ThreadMessageNodeInput[]
optional
runId
property
string
optional
state
property
ThreadSerializedState
optional
threadId
property
string
optional
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
DeclarationView source
threadMachinets
export declare const threadMachine: ThreadMachine;
DeclarationView source
ThreadMachinets
type ThreadMachine = Machine<ThreadInput, ThreadStateValue, ThreadContext, ThreadEvent, ThreadCommand>;
DeclarationView source
ThreadMessageNodeInputts
type ThreadMessageNodeInput = {
readonly id: string;
readonly parentId?: string;
};
Name
Kind
Type
Requirement
id
property
string
required
parentId
property
string
optional
Name
id
Kind
property
Type
string
Requirement
required
Name
parentId
Kind
property
Type
string
Requirement
optional

ThreadNode

type
DeclarationView source
ThreadNodets
type ThreadNode = {
readonly id: string;
readonly parentId?: string;
readonly childIds: readonly string[];
};
Name
Kind
Type
Requirement
childIds
property
readonly string[]
required
id
property
string
required
parentId
property
string
optional
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
DeclarationView source
ThreadQueueItemts
type ThreadQueueItem = {
readonly id: string;
readonly anchorId?: string;
};
Name
Kind
Type
Requirement
anchorId
property
string
optional
id
property
string
required
Name
anchorId
Kind
property
Type
string
Requirement
optional
Name
id
Kind
property
Type
string
Requirement
required
DeclarationView source
ThreadQueueLanets
type ThreadQueueLane = "steer" | "queue";
DeclarationView source
ThreadQueuests
type ThreadQueues = {
readonly steer: readonly ThreadQueueItem[];
readonly queue: readonly ThreadQueueItem[];
};
Name
Kind
Type
Requirement
queue
property
readonly ThreadQueueItem[]
required
steer
property
readonly ThreadQueueItem[]
required
Name
queue
Kind
property
Type
readonly ThreadQueueItem[]
Requirement
required
Name
steer
Kind
property
Type
readonly ThreadQueueItem[]
Requirement
required
DeclarationView source
threadReplaySequencets
export declare const threadReplaySequence: readonly ThreadEvent[];
DeclarationView source
threadSelectorsts
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
branchChildren
property
(snapshot: ThreadSnapshot, id: string) => readonly string[]
required
branches
property
(snapshot: ThreadSnapshot, id: string) => readonly string[]
required
capabilities
property
(snapshot: ThreadSnapshot) => ResolvedThreadCapabilities
required
editingMessageId
property
(snapshot: ThreadSnapshot) => string | undefined
required
isBusy
property
(snapshot: ThreadSnapshot) => boolean
required
messagesToHead
property
typeof messagesToHead
required
queueLengths
property
(snapshot: ThreadSnapshot) => { steer: number; queue: number; }
required
runValue
property
(snapshot: ThreadSnapshot) => RunValue
required
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
DeclarationView source
ThreadSerializedStatets
type ThreadSerializedState = {
readonly value: ThreadStateValue;
readonly context: ThreadContext;
};
Name
Kind
Type
Requirement
context
property
ThreadContext
required
value
property
ThreadStateValue
required
Name
context
Kind
property
Type
ThreadContext
Requirement
required
Name
value
Kind
property
Type
ThreadStateValue
Requirement
required
DeclarationView source
ThreadSnapshotts
type ThreadSnapshot = Snapshot<ThreadStateValue, ThreadContext>;
DeclarationView source
ThreadStateValuets
type ThreadStateValue = "ready" | "busy";