Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/lib/onboard/machine/definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ONBOARD_MACHINE_STATE_IDS,
ONBOARD_MACHINE_TERMINAL_STATE_IDS,
} from "./definition";
import { ONBOARD_SESSION_STEP_TO_MACHINE_STATE } from "./events";

const expectedStateOrder = [
"init",
Expand Down Expand Up @@ -65,6 +66,16 @@ describe("onboard machine definition", () => {
]);
});

it("derives the session step mapping from state definitions", () => {
const mappingFromDefinitions = Object.fromEntries(
ONBOARD_MACHINE_STATE_DEFINITIONS.flatMap((definition) =>
"stepName" in definition ? [[definition.stepName, definition.state]] : [],
),
);

expect(ONBOARD_SESSION_STEP_TO_MACHINE_STATE).toEqual(mappingFromDefinitions);
});

it("keeps progress metadata attached only to state-backed steps", () => {
for (const definition of ONBOARD_MACHINE_STATE_DEFINITIONS) {
if (!("progress" in definition)) continue;
Expand Down
32 changes: 20 additions & 12 deletions src/lib/onboard/machine/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@
import type { JsonObject, JsonValue } from "../../core/json-types";
import { redactSensitiveText, redactUrl } from "../../security/redact";
import type { HermesAuthMethod, Session } from "../../state/onboard-session";
import {
ONBOARD_MACHINE_STATE_DEFINITIONS,
type OnboardMachineStateWithStepDefinition,
} from "./definition";
import type {
OnboardMachineContext,
OnboardMachineEventType,
OnboardMachineState,
} from "./types";

export const ONBOARD_SESSION_STEP_TO_MACHINE_STATE = {
preflight: "preflight",
gateway: "gateway",
provider_selection: "provider_selection",
inference: "inference",
sandbox: "sandbox",
agent_setup: "agent_setup",
openclaw: "openclaw",
policies: "policies",
} as const satisfies Readonly<Record<string, OnboardMachineState>>;

export type OnboardSessionStepName = keyof typeof ONBOARD_SESSION_STEP_TO_MACHINE_STATE;
type OnboardSessionStepDefinition = OnboardMachineStateWithStepDefinition;

export type OnboardSessionStepName = OnboardSessionStepDefinition["stepName"];

type OnboardSessionStepToMachineState = {
readonly [StepName in OnboardSessionStepName]: Extract<
OnboardSessionStepDefinition,
{ stepName: StepName }
>["state"];
};

export const ONBOARD_SESSION_STEP_TO_MACHINE_STATE = Object.fromEntries(
ONBOARD_MACHINE_STATE_DEFINITIONS.flatMap((definition) =>
"stepName" in definition ? [[definition.stepName, definition.state]] : [],
),
) as OnboardSessionStepToMachineState;

export interface OnboardMachineEvent {
version: 1;
Expand Down